Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Re: utilities in perl

Reply
Thread Tools

Re: utilities in perl

 
 
George Mpouras
Guest
Posts: n/a
 
      09-21-2013
# you may like it

#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
my $dir = exists $ARGV[0] && -d $ARGV[0] ? $ARGV[0] : './';
foreach(<$dir/*>){say "$_ is ", -d $_ ? 'directory':'file'}

 
Reply With Quote
 
 
 
 
J. Gleixner
Guest
Posts: n/a
 
      09-25-2013
On 09/24/13 19:46, Cal Dershowitz wrote:

> [...] For the purposes of the template, I basically
> want to hard code the directory at this point.


Or.. look at using Find::Bin. That way you could run
/home/blah/get_file1.pl .. instead of always being in
/home/blah and having to run ./get_file1.pl.. and the
templates could be relative to get_file1.pl.

 
Reply With Quote
 
 
 
 
J. Gleixner
Guest
Posts: n/a
 
      09-25-2013
On 09/25/13 12:37, J. Gleixner wrote:
> On 09/24/13 19:46, Cal Dershowitz wrote:
>
>> [...] For the purposes of the template, I basically
>> want to hard code the directory at this point.

>
> Or.. look at using Find::Bin. That way you could run
> /home/blah/get_file1.pl .. instead of always being in
> /home/blah and having to run ./get_file1.pl.. and the
> templates could be relative to get_file1.pl.
>

correction.. FindBin not Find::Bin.. sorry.
 
Reply With Quote
 
George Mpouras
Guest
Posts: n/a
 
      09-25-2013
>> Or.. look at using Find::Bin. That way you could run
>> /home/blah/get_file1.pl .. instead of always being in
>> /home/blah and having to run ./get_file1.pl.. and the
>> templates could be relative to get_file1.pl.
>>

> correction.. FindBin not Find::Bin.. sorry.



why the FindBin and not the File::Find ;


 
Reply With Quote
 
$Bill
Guest
Posts: n/a
 
      09-26-2013
On 9/25/2013 15:46, George Mpouras wrote:
>>> Or.. look at using Find::Bin. That way you could run
>>> /home/blah/get_file1.pl .. instead of always being in
>>> /home/blah and having to run ./get_file1.pl.. and the
>>> templates could be relative to get_file1.pl.
>>>

>> correction.. FindBin not Find::Bin.. sorry.

>
>
> why the FindBin and not the File::Find ;


Why find at all if you're not recursing ?

opendir/readdir is more straight forward and probably efficient.

Or a recursive sub using opendir/readdir if you need depth isn't
all that much more complicated.

 
Reply With Quote
 
J. Gleixner
Guest
Posts: n/a
 
      09-26-2013
On 09/25/13 17:46, George Mpouras wrote:
>>> Or.. look at using Find::Bin. That way you could run
>>> /home/blah/get_file1.pl .. instead of always being in
>>> /home/blah and having to run ./get_file1.pl.. and the
>>> templates could be relative to get_file1.pl.
>>>

>> correction.. FindBin not Find::Bin.. sorry.

>
>
> why the FindBin and not the File::Find ;
>
>


The part that was meant to address was:

[...] For the purposes of the template, I basically
want to hard code the directory at this point.

Specifically, calling getcwd..

That's where FindBin comes in handy -- when your templates
are relative to where your program is located. Many
times your dev directory/machine might have different
paths or maybe you want to run it from something else
and want to call /home/junk/abc.pl instead of having to do
'cd /home/junk; ./abc.pl' etc. Using FindBin will
give you a lot of flexibility and you could move/cp everything
to a different directory ( e.g. for production ) and not
have to change any code.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: utilities in perl $Bill Perl Misc 4 09-22-2013 11:22 AM
Perl CGI utilities? JWhite Perl Misc 5 07-05-2008 03:39 AM
Accessing Browser Utilities on LinkSys WAP11 Doug Miannay Wireless Networking 1 04-18-2005 06:51 AM
HTML text filters, display control, utilities _eee_ ASP .Net 3 02-28-2004 10:58 PM
Cisco Tools & Utilities JohnNews Cisco 3 10-28-2003 10:38 PM



Advertisments