Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Glob strange bahavor

by Sidhekin (Priest)
on Aug 21, 2006 at 12:57 UTC ( #568528=note: print w/replies, xml ) Need Help??


in reply to Glob strange behavior

if(defined (my $filename=(glob("$path*$_*.pkl"))))

Based on those extra parentheses, it looks like you're trying to call glob in list context (which would make more sense, too). But parentheses on the right hand side of assignment do not a list assignment make. Put them on the left hand side instead.

Also, an empty list assignment in scalar context is actually defined (zero, to be precise), so you likely want this:

if(my ($filename)=glob("$path*$_*.pkl"))

print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!

Replies are listed 'Best First'.
Re^2: Glob strange bahavor
by ikegami (Pope) on Aug 21, 2006 at 14:52 UTC
    He's checking if a file exists, so a simpler fix would be to use the command designed to check just that: -e (or -f).
    #!/usr/bin/perl use strict; use warnings; my $path='C:/dataset/'; my @sign_arr=('A1', 'A2', 'A3','A4', 'A5', 'A6', 'A7', 'A8', 'A9'); foreach (@sign_arr) { my $filename = "$path*$_*.pkl"; if (-e $filename) {print "$filename $_\n"} else {print "not found $_\n";} }

    Update: Ack, nevermind, I didn't notice his use of *. First post of the morning, sorry.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2020-10-26 22:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (254 votes). Check out past polls.

    Notices?