![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| perl -write values in a file to @array in perl | meghana | Shell Programming and Scripting | 12 | 07-17-2008 01:38 PM |
| PERL array spacing | Jamison | Shell Programming and Scripting | 3 | 07-17-2008 01:10 AM |
| split to array in perl | jaganadh | Shell Programming and Scripting | 3 | 07-06-2007 02:29 AM |
| hash,array and perl | new2ss | Shell Programming and Scripting | 3 | 05-23-2007 08:30 AM |
| appending to perl array | vivekshankar | UNIX for Dummies Questions & Answers | 7 | 06-03-2006 07:33 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
how to get last value in an array in perl
Hi,
I have a set of file names say: file1 file2 file3 .. filen I may just do a ls -l or however it works to read this list into an array... I need to pick the last file name that is "filen" from the list... your help is greatly appreciated.....hope im clear on my question... |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Code:
zsh-4.3.4% ls file1 file2 file3 file4 file5 zsh-4.3.4% perl -le'print $ARGV[-1]' file* file5 |
|
#3
|
|||
|
|||
|
Code:
ls file* | sort | tail -1 |
|
#4
|
||||
|
||||
|
Or
Code:
$ ls file1 file2 file3 file4 file5 $ set -- file*;echo $_ file5 Code:
set -- file* echo $_ Last edited by radoulov; 02-04-2008 at 09:03 AM. Reason: corrected |
|
#5
|
|||
|
|||
|
wow.. thanks for the really quick replies.. im doing this using a script tmp.pl ..
$ ls file1 file2 file3 file4 file5 $ set -- file*;echo $_ file5 can u please tell me how to write this in a script??? thanks again |
|
#6
|
||||
|
||||
|
If it's a perl script, use perl:
Code:
zsh-4.3.4% ls file1 file2 file3 file4 file5 temp.pl zsh-4.3.4% cat temp.pl #!/usr/bin/perl use warnings; @files = <file*>; print "$files[-1]\n"; zsh-4.3.4% ./temp.pl file5 |
|
#7
|
|||
|
|||
|
i have got a solution ... its little different but it works.....
my @files = glob("file*"); my $last_file_name = pop(@files); thanks for ur quick replies again........ |
|||
| Google The UNIX and Linux Forums |