Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: glob behavior

by Anonymous Monk
on Mar 20, 2012 at 08:45 UTC ( [id://960548]=note: print w/replies, xml ) Need Help??


in reply to glob behavior

Why it behaves itself different?

It probably doesn't :) put both loops in the same file and see what happens

Also, report your perl version and File::Glob version

Replies are listed 'Best First'.
Re^2: glob behavior
by vagabonding electron (Curate) on Mar 20, 2012 at 09:01 UTC
    I use ActivePerl v.5.14.1 on WinXP.
    The version of File::Glob is 1.12

    Update: I changed the loop to:
    for my $t (keys %address) { my $file = glob ("$address{$t}/Test*"); print "$t : $address{$t} : $file, \n###\n"; print "$t : $address{$t} : ", glob ("$address{$t}/Test*"), "\n---\ +n"; }
    It prints:
    A : U:/TEMP/TEMP/A : U:/TEMP/TEMP/A/Test01.txt, ### A : U:/TEMP/TEMP/A : U:/TEMP/TEMP/A/Test01.txt --- Use of uninitialized value $file in concatenation (.) or string at ... + line 17. D : U:/TEMP/TEMP/D : , ### D : U:/TEMP/TEMP/D : U:/TEMP/TEMP/D/Test04.txt --- C : U:/TEMP/TEMP/C : U:/TEMP/TEMP/C/Test03.txt, ### C : U:/TEMP/TEMP/C : U:/TEMP/TEMP/C/Test03.txt --- Use of uninitialized value $file in concatenation (.) or string at ... + line 17. E : U:/TEMP/TEMP/E : , ### E : U:/TEMP/TEMP/E : U:/TEMP/TEMP/E/Test05.txt --- B : U:/TEMP/TEMP/B : U:/TEMP/TEMP/B/Test02.txt, ### B : U:/TEMP/TEMP/B : U:/TEMP/TEMP/B/Test02.txt ---
Re^2: glob behavior
by vagabonding electron (Curate) on Mar 20, 2012 at 15:45 UTC
    ... and now after changing the line from
    my $file = glob ("$address{$t}/Test*");
    to
    my ($file) = glob ("$address{$t}/Test*");
    the output is as follows:
    A : U:/TEMP/TEMP/A : U:/TEMP/TEMP/A/Test01.txt, ### A : U:/TEMP/TEMP/A : U:/TEMP/TEMP/A/Test01.txt --- D : U:/TEMP/TEMP/D : U:/TEMP/TEMP/D/Test04.txt, ### D : U:/TEMP/TEMP/D : U:/TEMP/TEMP/D/Test04.txt --- C : U:/TEMP/TEMP/C : U:/TEMP/TEMP/C/Test03.txt, ### C : U:/TEMP/TEMP/C : U:/TEMP/TEMP/C/Test03.txt --- E : U:/TEMP/TEMP/E : U:/TEMP/TEMP/E/Test05.txt, ### E : U:/TEMP/TEMP/E : U:/TEMP/TEMP/E/Test05.txt --- B : U:/TEMP/TEMP/B : U:/TEMP/TEMP/B/Test02.txt, ### B : U:/TEMP/TEMP/B : U:/TEMP/TEMP/B/Test02.txt ---

      Once again you're dealing with different contexts. my $file = glob ... evaluates glob in scalar context, rendering it an iterator function, and my ($file) = glob ... evaluates glob in list context, rendering it a list function that returns a list, which can be empty.


      Dave

        Thank you Dave,
        in fact I did not intend to object but rather to show that I understood the difference now :-)
        VE

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-03-19 04:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found