On Monday, June 2, 2003, at 06:53 AM, zentara wrote:

Say I have an array like:

@somename = (1,2,3,4,5);

and I want to write that array to a file, but I
want the file named automatically by just
dropping the @ off of the @somename.
How would you go about doing it?

Well, if your still inside your code, you know the name of the variable, right? Couldn't you just create a file named 'somename'? You typed it once to name the variable, seems like you could type it again to name the file.


Also the reverse: take a filename like "somename"
and load it to an array @somename just by some
concantation like @{'somename'}.

The @{'somename'} seems to work, but not with strict.

If you dump it out using something like:


perl -MData::Dumper -e 'print Data::Dumper->Dump([[1..5]], ["*somename"]), "\n";'

You could simply do 'path/to/something.pl'; to get it back, I believe. This shouldn't upset strict.

However, this, to me, is a textbook perfect example of why the statement, "Always use strict," is patently false. The strict pragma is three tools in one, but you may not need all of those tools all the time. Does your dentist use a drill every time they clean your teeth? If Perl supports a feature and you aren't using it because strict would complain, that's just silly. You turned it on in the first place, remember?

use strict; # ask Perl to keep us honest

# and then later...

{ # localize our rules change here
no strict 'refs'; # tell Perl, I know what I'm doing here, so stay out of my way
# something including your @{'somename'} construct
} # scope ends and strict is back in business


Never feel bad about changing the rules, as long as you understand why you are changing them.

James


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to