Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: regex issue

by Roy Johnson (Monsignor)
on Mar 24, 2004 at 16:29 UTC ( #339460=note: print w/replies, xml ) Need Help??


in reply to regex issue

What you're suggesting requires symbolic references. It's usually better to do it with a hash, where you'd end up with
$hash{'A'} = '33'; $hash{'B'} = '22';

The PerlMonk tr/// Advocate

Replies are listed 'Best First'.
Re: Re: regex issue
by tilly (Archbishop) on Mar 24, 2004 at 16:43 UTC
    How about offering the questioner some (even untested) code?
    use strict; # always # The hash that we'll populate my %value_of; # You have to open the file and read it... my $file = "your file name"; open(FILE, "<", $file) or die "Cannot read '$file': $!"; my $last_variable; while (<FILE>) { # Remove the newline chomp; if (s/^\s+//) { # This was indented, assign it to the hash $value_of{$last_variable} = $_; } else { # This was not indented, it was a variable name $last_variable = $_; } } # %value_of now has the data.
      How about offering the questioner some (even untested) code?
      The question wasn't very detailed, so my answer wasn't very detailed. I don't think that answerers should put more into this than questioners.

      The PerlMonk tr/// Advocate
        If you think that a question deserves a useless answer, then why bother answering?

        Furthermore we were given exact input and an exact desired result. What additional detail could have made the question any clearer?

        My attitude is that unless I am willing to provide an answer that I believe will be helpful, I won't answer. When the question indicates to me that the questioner may not know much Perl at all, my definition of a useful answer becomes very detailed. A higher level summary is OK when I think the questioner will understand it.

        And a final note. Your answer had a severe error. You cannot possibly do exactly what the questioner requested using symbolic references. I'll leave it as an exercise for you to test and/or read documentation to discover why.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://339460]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2022-01-22 12:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (62 votes). Check out past polls.

    Notices?