![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| perl -write values in a file to @array in perl | meghana | Shell Programming and Scripting | 27 | 06-07-2009 05:05 PM |
| Remove an element from an array in PERL | chriss_58 | Shell Programming and Scripting | 3 | 06-06-2008 05:08 AM |
| A final question! Compare character with each array element | rorey_breaker | Shell Programming and Scripting | 1 | 09-28-2007 09:26 AM |
| array type has incomplete element type | jaganadh | High Level Programming | 1 | 07-24-2007 03:54 AM |
| accessing my first element of array | afadaghi | Shell Programming and Scripting | 4 | 09-29-2005 04:43 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Perl delete an element from array
Probably I am not seeing it or I am not using the "delete" correctly I had the following codes but it does not work for me
Code:
#!/bin/perl -w
...
@sysFile1 = (a_b, a_c, a_d);
@sysFile2 = (a_c, a_e, b_f);
foreach $line1 (@sysFile1){
trim(\$line1);
(my $tmp1, my $tmp2) = split/_/, $line1;
foreach $line2 (@sysFile2) {
trim(\$line2);
(my $tmp3, my $tmp4) = split/_/,$line2;
if (($tmp1 eq $ $tmp3) && ($tmp2 eq $tmp4)) {
print "found\n";
} else {
print "not found\n";
}
delete $sysFile1[1];
}
}
Code:
$ test.pl delete argument is not a HASH element or slice at test.pl line 50 Last edited by ahtat99; 01-17-2007 at 04:34 PM.. |
|
||||
|
ops, my fault, I was typing this on the fly while converting most of my codes, because of the policy issue,
Actually the $array1 would be $sysFile1. I will make an update to the snipplets, thank you, nathan, for taking your time to review my question. |
|
||||
|
I don't understand what you are trying to do, actually.
Just bear in mind: - To really delete an item from an array, such as (1, 2, 3) -> (1, 3), use splice(). - delete() simply sets the elements as "undef". Unless the elements happen to appear at the end of the array, they will not be removed, and is usually not what you want. delete() is usually more meaningful for hashes to remove hash items, NOT array items. You can look at this illustration: Code:
[bernardchan@bernardchan ~]$ perl -MData::Dumper -w -e '@a = (1,2,3); delete $a[0]; print Dumper [@a]'
$VAR1 = [
undef,
2,
3
];
[bernardchan@bernardchan ~]$ perl -MData::Dumper -w -e '@a = (1,2,3); splice(@a, 0, 1); print Dumper [@a]'
$VAR1 = [
2,
3
];
|
![]() |
| Bookmarks |
| Tags |
| awk, awk trim, trim, trim awk |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|