Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > parameter expansion in perl

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-19-04, 14:56
Daryl Lim Daryl Lim is offline
Registered User
 
Join Date: May 2004
Posts: 11
parameter expansion in perl

Hi all.

I am trying to use Perl to locate the longest filename in a directory and a subdirectory,

what is the equivalance of the parameter expasnion to bash script to do:

to extract "file1" from "/root/file1.txt"


in bash script, i use

${file##.*} , then ${file%.} to extract


thanks
daryl
Reply With Quote
  #2 (permalink)  
Old 06-20-04, 11:28
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 9,573
I'd use:
Code:
@files = glob($directory);

-PatP
Reply With Quote
  #3 (permalink)  
Old 07-07-04, 23:25
senza_nome senza_nome is offline
Registered User
 
Join Date: Jun 2004
Location: Nowhere Near You
Posts: 89
Something like this perhaps
Code:
#!\user\bin\perl -w use File::Find; use File::Basename; # Current directory if nothing else was specified @ARGV=qw(') unless @ARGV; my($s_LongestFileName); # Set $s_Name to the filename and extension of the file under scrutiny; Set $s_LongestFileName to $s_FileName if $s_FileName is longer find (sub{ my($s_FileName)=basename($File::Find::name); $s_LongestFileName=$s_FileName if length($s_LongestFileName) < length($s_FileName);},@ARGV); print length($s_LongestFileName).":$s_LongestFileName\n";
Reply With Quote
  #4 (permalink)  
Old 07-08-04, 18:06
senza_nome senza_nome is offline
Registered User
 
Join Date: Jun 2004
Location: Nowhere Near You
Posts: 89
Assuming that the extension of File1.txt.bak is .bak and not .txt.bak, you should be able to use
Code:
#!\user\bin\perl -w use File::Find; use File::Basename; # Current directory if nothing else was specified @ARGV=qw(.) unless @ARGV; my($s_LongestFileName); # Set $s_Name to the filename and extension of the file under scrutiny; Set $s_LongestFileName to $s_FileName if $s_FileName is longer find (\&CheckThisFile,@ARGV); print length((fileparse($s_LongestFileName,'\.[^.]*'))[0]).":$s_LongestFileName\n"; sub CheckThisFile { my($s_FileName)=$File::Find::name; $s_LongestFileName=$s_FileName if length((fileparse($s_LongestFileName,'\.[^.]*'))[0]) < length((fileparse($s_FileName,'\.[^.]*'))[0]); };
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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