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

Re: file listing within skript not working

by moritz (Cardinal)
on Jan 30, 2013 at 10:39 UTC ( #1016019=note: print w/ replies, xml ) Need Help??


in reply to file listing within skript not working

There's no need to shell out to ls to get a list of files, you can simply say

my @files = glob "$datenDir/*.xml";

(assuming that $datenDir doesn't contain whitespaces or other nasty stuff; but that would a problem with your approach too).

So why is the backtick-ls working with perl -e but not within a script?

I'm very sure it's not script vs. -e, but that there is some other difference. Is the directory the same in both cases? Is the script run as the same user, with the same security context (if you use selinux) as your one-liner?


Comment on Re: file listing within skript not working
Select or Download Code
Re^2: file listing within skript not working
by McSvenster (Initiate) on Jan 30, 2013 at 11:04 UTC

    Thanks a lot for Your help! I'll ask our server-admins about selinux. I am pretty sure you are right. When I changed the script to

    my @files = glob "$datenDir/*.xml";
    it does not even write anything into the logfile. So I think the listings within scripts might be forbidden.

    And thanks for directing me to "glob". Don't know why I didn't use it - I think I need something to drink :-)

      Well said moritz ++

      McSvenster Perl has many ways to do things,you can also use readdir() function this way,

      use strict; use warnings; use Data::Dumper; opendir (DIR, "/home/vinoth/"); my @files = grep /\.xml$/, readdir DIR; print Dumper \@files;

      I am not telling this is the best way, but its also one of the way.

        It's getting more and more confusing for me...

        But maybe I found the critical point: When I use the backticks perl writes to the logfile until the program comes to the line with the backticks. But when I use "glob" instead, perl executes the whole program before it performs any file-writing.

        Is this right? And more important: Can you explain it to me? (you see, I am a beginner...)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2014-07-31 21:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (253 votes), past polls