http://qs321.pair.com?node_id=81289


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!