logo       

Sponsor
FREE Network Mapping Tool for Microsoft® Office Visio® Professional 2007
Don't map your network by hand - let LANsurveyor Exx press for Microsoft Visio Professional 2007 automatically create network diagrams for you!

RE: Beyond Book Learning - the problem of Re: array numerical name...: msg#00292

lang.perl.beginners

Subject: RE: Beyond Book Learning - the problem of Re: array numerical name...

> On Tuesday, April 30, 2002, at 07:32 , David Gray wrote:
> [..]
> > my $fred = 'one,two,three,four';
> > my $a = 0;
> > @{"array$a"} = split ',', $fred;
> >
> > for(0..3) {
> > print ${"array$a"}[$b]
> > }
>
> File "untitled text 2"; Line 21: Name "main::b" used only
> once: possible
> typo
> File "untitled text 2"; Line 18: Can't use string ("array0")
> as an ARRAY
> ref while "strict refs" in use
>
>
> yeah I can clean that up with
>
> my $fred = 'one,two,three,four';
> my $a = 0;
> no strict 'refs';
> @{"array$a"} = split ',', $fred;
>
> foreach my $b(0..3) {
> print ${"array$a"}[$b] ."\n"
> }
>
> so as to get the output
>
> one
> two
> three
> four

Yeah, that would be a clever typo, like it says in the cryptic error
message. Sorry about that.

> All of which drives me back to the question - why did we compel
> ourselves to have to insert the
>
> "no strict 'refs';"
>
> given the quandery:
>
> > basically i want to name an array with a subscript ie
> > world0[0] and world1[0] the 0/1 being a variable, i have tried to
> > produce a simple example....
>
>
> why take the convolutions???

<http://www.m-w.com/cgi-bin/dictionary?book=Dictionary&va=quandery>
Question, perhaps?
<http://www.m-w.com/cgi-bin/dictionary?book=Dictionary&va=convolutions>
3. a complication or intricacy of form, design, or structure

I don't use these "convolutions" of perl for large programming projects
or for sensitive cgi scripts, unless they are in a very otherwise static
and controlled environment, like in that example. I also find that it's
only more confusing to be sesquipedalian in response to posts that only
need a simple, clear answer.

> What have we added to the long term maintainability of the
> code by carbuncling it like this????

<http://www.m-w.com/cgi-bin/dictionary?book=Dictionary&va=carbuncling>
I'll assume you mean that code is confusing. But it's not. It's very
simple. It's a very easy way to perform aggregate functions on several
sets of data, as long as you're careful to make sure your code doesn't
have any stupid side effects, like what Jeff described.

> Why not compel the author down the road to understanding
> how to do good data structures???

Everyone else who responded to the thread did that, and very well I
thought. Perhaps, however, the OP has a simple script that would be
simplified even more if he knew how to use dynamic variables. Sometimes,
when a simple script is the easiest solution to the problem, it's worth
more to just get it working than to spend time developing a complex data
structure.

-dave





Only community members can participate in forum threads. You must Register or log in to contribute.

<Prev in Thread] Current Thread [Next in Thread>
Sponsor
FREE Network Mapping Tool for Microsoft® OfficeVisio Professional 2007
Don't map your network by hand - let LANsurveyor Express for Microsoft Visio Professional 2007
automatically create network diagrams for you!
Google Custom Search

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation

Home | sitemap | advertise | OSDir is an inevitable website. super tiny logo