[perl] array eintrag löschen

Post Reply
Message
Author
stefansf
Posts: 84
Joined: 28. Aug 2002 19:40

[perl] array eintrag löschen

#1 Post by stefansf »

Hallo,

kennt Jemand von euch eine Möglichkeit einen bestimmten Eintrag im Array, z.B. $array[56], komplett zu löschen?
push, popt, usw. tun ihre Dienste ja immer nur am Anfang bzw. Ende eines Arrays.

MfG Stefan

ratte

Re: [perl] array eintrag löschen

#2 Post by ratte »

<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">
#!/usr/bin/perl -w
# perldoc perlfunc: look for 'splice ARRAY,OFFSET,LENGTH,LIST'

@array=("1","2","3");

print "before removing element 2:\<!--no-->n";
foreach (@array) {
print "$_\<!--no-->n"
}

$array[<!--no-->1]=undef; # unescessary, because of next line
splice @array,1,1;

print "after removing element 2:\<!--no-->n";
foreach (@array) {
print "$_\<!--no-->n"
}
</font><hr></pre></blockquote>

btw: ub code sucks.

ratte

Post Reply