Under each directory, there would be many files like...
.
.
.
abc.200801.dat
abc.200802.dat
abc.200803.dat
abc.200804.dat
I'm writing a perl script, in which part of the logic is to get the stat() of the latest file in the corresponding directory. (in this case I need to get stat() of abc.200804.dat
So, first I'm getting the directory and then chdir to that location and doing a ls -ltr with the wild card file names and storing them in array. Then using $
The problem is, I think when I'm trying to get the last changed file into the array element, its storing the latest file in the last element, but I think its appending new line to the element along with file name. So, the stat($f_nme) isn't working.
Can you please let me know what I'm missing?
Thanks!
Basically what he said... Use chomp($f_nme[-1]) first, then assign it. Use chomp() above where you get the directory list from your input file too... Is safer. chop() will strip the last char of a string ALWAYS. chomp() strips only if is a LINE ENDING, so is much safer usually if you are not always SURE that the last char of your string is the line ending you want to remove....
Basically what he said... Use chomp($f_nme[-1]) first, then assign it. Use chomp() above where you get the directory list from your input file too... Is safer. chop() will strip the last char of a string ALWAYS. chomp() strips only if is a LINE ENDING, so is much safer usually if you are not always SURE that the last char of your string is the line ending you want to remove....
I should have mentioned it.... I've used both chomp($list_files[-1]) and chop($list_files[-1]). It doesn't seem to work.
It doesn't assign any value to $f_nme.
And chomp(($list_files[-1]) returns "1" ?!
Anyways, I have used the way cbhikong suggested and it worked. Thanks!
Hi All,
need help with reading the array and sum of the array elements.
given an array of integers of size N . You need to print the sum of the elements in the array, keeping in mind that some of those integers may be quite large.
Input Format
The first line of the input consists of an... (1 Reply)
Hi,
I can't find out how to create correct code to get multiplication of each elements of array. Let's say I enter array into command line (2 3 4 5 6 8) and i need output 2*3*4*5*6*8=5760.
I tried this one, but answer is 0.
for i in $@; do
mult=$((mult*i))done
echo "mult: " $mult
... (4 Replies)
Experts,
I am looking to compare elements of 2 array using perl. Below is not the actual code but logic wise something like this.
my $version = "MYSQlcl-5.2.4-264.x86_64"; <-- split this word into array as (5 2 4 264) ( which is to extract only the version number from the package name)
my... (1 Reply)
Hi,
I have an array containing following sample information
@array = qw (chr02 chr02 chr02 chr02 chr02 chr03 chr03 chr04 chr04 chr05 chr05 chr05 chr07 chr07) I need to replace all duplicate entries by an underscore to get the following output@array = qw (chr02 _ _ _ _ chr03 _ chr04 _ chr05 _ _... (4 Replies)
Hello,
I have the following perl array:
@longname = (Fasthernet0/0 Fasthernet0/1 Serial0/1/0 Serial0/2/1 Tunnel55 Tunnel77)
with the followinh array:
@shortname = (Fa0/0 Fa0/1 Se0/1/0 Se0/2/1 Tu55 Tu77)
in other words, I need to remove the following from each element in the array... (4 Replies)
How can I get my array to understand the double-quotes I'm passing into it are to separate text strings and not part of an element? here's what I'm working with...
db2 -v connect to foo
db2 -x "select '\"' || stats_command || '\",' from db2law1.parallel_runstats where tabname = 'BAZ'"
set... (4 Replies)
I need to use array elements while pattern matching.
@myarr = (ELEM1, ELEM2, ELEM3);
following is the statement which I am using in my code. Basically I want to replace the ELEM1/2/3 with other thing which is mentioned as REPL here.
if (condition) {
s/(ELEM1|ELEM2|ELEM3): REPL: /;
}
I... (3 Replies)
Hi,
My doubt is how to access array elements..
Situation is as below:
#!/bin/ksh
set -x
typeset -i x=0
typeset -i y=0
typeset -i BID=0
typeset -i count=0
while ] ; do
x=`expr $x + 1`;
hwmgr show scsi > scsi.tmp
while read line; do
set... (1 Reply)
I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows:
$count = 0;
while ( $count < $#test )
{
`sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`;
`cat 0 >... (2 Replies)