Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: regex issue

by Roy Johnson (Monsignor)
on Mar 24, 2004 at 16:29 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2024-03-28 12:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found