Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Scoping Variables

by mothra (Hermit)
on May 17, 2001 at 20:10 UTC ( #81289=note: print w/replies, xml ) Need Help??

in reply to Scoping Variables

This, and posts like it, bother me.
I'm going to make some assumptions from things I've read in Programming perl, and in the monastary Please correct me if I'm wrong:
sub meat_and_potatoes_of_program { while (<my_file>){ /(\w{3}\s+\w{3}\s+\d{1,2}/;

You're not memorizing anything here, because you haven't closed the parentheses. You must actually test code before you post it (unless you're merlyn or tilly or one of the several other clueful hackers among the Monks).

my $date = $1; print "date \n <br>";
Okay...and that print statement served what purpose in illustrating your problem?
I have also tried:
sub the_meat_and_potatoes_of_program{ my $pass_down_date = 1
Which -- again -- serves what purpose?

Please be more careful the next time you post a question here. Ensure that your code is exactly the same as that which you claim "doesn't work" (ie. you've tested it and are able to show precisely what the problem is via the errors perl gives you, or the output you're getting and how it differs from what you're expecting), and ideally that your spelling is correct, and that the layout of your post doesn't assault one's visual cortex (thanks to The Damian for that one, and for Text::Autoformat :).

My intention isn't to flame, but rather to provide advice that will help you get the most helpful and accurate replies, and keep the content of The Monastery high.

Replies are listed 'Best First'.
Re: Re: Scoping Variables
by Clachair (Acolyte) on May 18, 2001 at 07:28 UTC
    Ahem, er, am I missing something really simple here?
    I wouldn't expect this statement to work:-
    if ($foo) { print "the date is... $date \n <br>"; }
    at least not on my Perl version.

    Surely, it should be:-
    if ($foo) { print "The date is...", $date, "\n <br>"; }

    Never lick a gift horse in the mouth.
      Yes, you are missing something really simple here. It's called interpolation and it happens inside double quotes. Put this in a script and run it. $x=1; print 'single quoted dollar x is $x'; print "\n"; print "double quoted dollar x is $x"; print "\n"; perl -e '
        WHOOPS, Sorry. That should have been
        $x=1; print 'single quoted dollar x is $x'; print "\n"; print "double quoted dollar x is $x"; print "\n";
        Many thanks.
        Neither of my enormous tomes containing Perls of wisdom explained that one!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2022-05-29 05:51 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (101 votes). Check out past polls.