Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

ARGV *.* importing problems

by Monkomatic (Sexton)
on Apr 30, 2011 at 16:24 UTC ( [id://902210]=perlquestion: print w/replies, xml ) Need Help??

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

I know for a fact i got this to work sometime in my life. I remember doing it. But im beginning to think maybe it was a unix system because I cant seem to get to work on XP any help would be appreciated.

Simply trying to get all the file handles in the directory loaded into argv by using *.* to import all the file names.

c:>Program.pl *.*

use threads; use threads::shared; use Data::Types qw(:all); use Price_calc qw[ $stringsent $stringsentback @arraysent @arraysentba +ck @arraysentprice @arraysentbackprice]; use IO::Tee; # perl trackit.pl *.* # ========================================= Set changables my @threads; my $maxthreadama=4; # MAX NUMBER OF simultanous Lookup Calls my $keepgoing="keepgoing"; my @trackinglist;my @trackingfilelist;my @datain;my $filename; foreach $file (@ARGV) { if ($file =~ /txt/) {push (@trackinglist,$filename);} } print "@ARGV\n"; print "T1:@trackinglist \n"; system("pause");
T1:*.*

Anyone have a clue? I cant find a solution on google because * doesnt search very well and asterisk is some kind of software or coding platform. Did try before asking here though.

Does anyone know a cpan module to load all directory filenames into a variable? i can do it that way i suppose. But seems like perl should do this.

Replies are listed 'Best First'.
Re: ARGV *.* importing problems
by Corion (Patriarch) on Apr 30, 2011 at 16:30 UTC

    You need to expand the shell wildcards yourself. I recommend using File::Glob::bsd_glob:

    use File::Glob qw(bsd_glob); BEGIN { # expand all wildcards given on the command line @ARGV = map { bsd_glob $_ } @ARGV; };

    This is needed because expanding wildcards is considered a job of the shell on unixish systems, while on Windows, it is left up to the program to expand its wildcard arguments.

Re: ARGV *.* importing problems
by Util (Priest) on Apr 30, 2011 at 18:53 UTC

    The Win32::AutoGlob module is ideal for this; it implements roughly what Corion++ suggested, for exactly the reasons he mentioned.

Re: ARGV *.* importing problems
by cdarke (Prior) on Apr 30, 2011 at 17:24 UTC
    Also see the built-in glob, but this can have issues with whitespace, so File::Glob is usually safer.

    Note that the glob construct *.* does not necessarily get all the files in the current directory, it only gets those whose names contain a dot. That will not include many files taken from UNIX, or most sub-directories (it is rare to see a dot in a directory name).
      Also see the built-in glob, but this can have issues with whitespace, so File::Glob is usually safer.
      Safer? In the documentation you linked it says: Beginning with v5.6.0, this operator is implemented using the standard File::Glob extension.
        While it is true that the documentation says that, consider:
        my @files = glob('C:/Program Files/*'); print "@files\n";
        gives:
        C:/Program
        whereas:
        use File::Glob qw(glob); my @files = glob('C:/Program Files/*'); print "@files\n";
        gives:
        C:/Program Files/7-Zip C:/Program Files/ATI C:/Program Fil...
        etc. ad nauseum.
        This on ActiveState perl 5.12.3 64-bit Windows 7, but has been the same siince at least 5.6.0. I get similar results on Linux on 5.8.8.
Re: ARGV *.* importing problems
by Anonymous Monk on Apr 30, 2011 at 16:55 UTC
Re: ARGV *.* importing problems
by Monkomatic (Sexton) on Apr 30, 2011 at 19:01 UTC

    Thank you Kindly for all your help. Go go Microslow.

    I had finally finished all the hard code concerning threads and reading up on the new changes past 5.8.

    Then i spent the last hour+ banging my head on this stupid thing and searching google before giving up and asking here.

    Doesn't it seem it always works that way with code? Hard stuff is easy and then theres the bug or one thing you cant seem to nail down holding it back.

    Thanks again.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-24 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found