- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- perl: delete element in an array?
Operating System - HP-UX
1820635
Members
1777
Online
109626
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-14-2010 09:54 AM
тАО06-14-2010 09:54 AM
Hey;
I find myself having to delete an arbitrary element in an array - not necessarily the first nor the last.
Is there some clever way of doing that short of
for (my $x=0; $x<$curr; $x++)
{ $new[$x] = $old[$x]; }
for (my $x=$curr+1; $x<$#old; $x++)
{ $new[$x-1] = $old[$x]; }
@old = @new;
And, no, I don't know if that works yet - that was just done off the fly. I'm curious if there's a different algorithm for doing this out there somewhere..
Thanks for any hints/tips/suggestions.
Doug
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
I find myself having to delete an arbitrary element in an array - not necessarily the first nor the last.
Is there some clever way of doing that short of
for (my $x=0; $x<$curr; $x++)
{ $new[$x] = $old[$x]; }
for (my $x=$curr+1; $x<$#old; $x++)
{ $new[$x-1] = $old[$x]; }
@old = @new;
And, no, I don't know if that works yet - that was just done off the fly. I'm curious if there's a different algorithm for doing this out there somewhere..
Thanks for any hints/tips/suggestions.
Doug
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Solved! Go to Solution.
- Tags:
- Perl
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-14-2010 10:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-14-2010 10:19 AM
тАО06-14-2010 10:19 AM
Re: perl: delete element in an array?
Hi (again):
Sorry, I meant to add this too!
# perl -le '@a=qw(a b c d e f);splice(@a,3,2);print @a'
abcf
Regards!
...JRF...
Sorry, I meant to add this too!
# perl -le '@a=qw(a b c d e f);splice(@a,3,2);print @a'
abcf
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-14-2010 10:37 AM
тАО06-14-2010 10:37 AM
Re: perl: delete element in an array?
Hey;
That works pretty well; here's the playing around I did. This'll be exactly what I need. I appreciate it.
Doug
my @a = qw (one two three four five six seven eight nine ten );
my @b = @a;
my $cur = $ARGV[0];
print "$a[$cur]\n";
@a = splice(@b, 0, $cur);
print "A: @a" . "\n";
print "B: @b" . "\n";
push(@a, splice(@b,1));
print "A: @a" . "\n";
print "B: @b" . "\n";
./junk 3 # results in:
four
A: one two three
B: four five six seven eight nine ten
A: one two three five six seven eight nine ten
B: four
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
That works pretty well; here's the playing around I did. This'll be exactly what I need. I appreciate it.
Doug
my @a = qw (one two three four five six seven eight nine ten );
my @b = @a;
my $cur = $ARGV[0];
print "$a[$cur]\n";
@a = splice(@b, 0, $cur);
print "A: @a" . "\n";
print "B: @b" . "\n";
push(@a, splice(@b,1));
print "A: @a" . "\n";
print "B: @b" . "\n";
./junk 3 # results in:
four
A: one two three
B: four five six seven eight nine ten
A: one two three five six seven eight nine ten
B: four
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP