Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

problems with global $1

by neo1491 (Beadle)
on Oct 22, 2007 at 18:23 UTC ( #646533=perlquestion: print w/replies, xml ) Need Help??

neo1491 has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: problems with global $1
by brian_d_foy (Abbot) on Oct 22, 2007 at 20:12 UTC

    Every line that has $1 on it has an uninitialized value, and it's not $1. This isn't your real program though; this doesn't get past use strict since you haven't declared the variables, and you've got a couple of syntax errors. Perhaps your test program was supposed to be:

    use strict; use warnings; $_ = "ArraySize 4285"; my $luns_per_array = 10; my $logical_size; # useless variable? if ( /^ArraySize (.+)/ ) { print "\nArray: " . $1 . " yields a LUN of " . int($1/$luns_per_ar +ray) . "GB\n" ; $logical_size = int($1/2); if ( ( $logical_size * $luns_per_array ) == $1 ) { {$logical_size--;} } }
    --
    brian d foy <brian@stonehenge.com>
    Subscribe to The Perl Review
Re: problems with global $1
by andyford (Curate) on Oct 22, 2007 at 18:34 UTC

    Perhaps your regular expression is not matching anything, leaving $1 uninitialized?

    non-Perl: Andy Ford

Re: problems with global $1
by eff_i_g (Curate) on Oct 22, 2007 at 19:01 UTC
Re: problems with global $1
by neo1491 (Beadle) on Oct 22, 2007 at 18:46 UTC
    the line "ArraySize 4285" is identified by the regular expression. would'nt . $1. initialize $1 with the value "4285"... which is the string next to "ArraySize"?

      If the string is at the beginning of the line: you have the '^' at the beginning your regex. You also have to make sure that what you think is a single space is really a single space. Try changing the space in the regex to, say, '\s+' to match any kind and amount of white space. There are probably other things that could go wrong that I haven't thought of...

      non-Perl: Andy Ford

      I might try answering your question once you have formatted your OP as suggested by eff_i_g below.

      Until then, I'm afraid, I just don't understand it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://646533]
Approved by Joost
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2021-04-14 06:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?