Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A few questions :) splice and split 3

Status
Not open for further replies.

travs69

MIS
Dec 21, 2006
1,431
US
Can these two steps be combined into one (I need to remove the last 2 elements and the first element)? I thought I could do -2,3 but it doesn't work that way.

splice(@array,-2,2);
splice(@array,0,1);

Can these two be combined?
my @array = $telnet->waitfor('/]/');
my @newarray = split /\n/, $array[0];

I tried
@newarray = split(/\n/, $telnet->waitfor('/]/')); (And a few variations but everything is coming back as a 1).

Thanks in advance as always!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Can't see anything else as
Code:
@array=@array[1..$#array-2];
(no warning issued if array too short, simply returns the null list).
For the second one this one should work
Code:
my@newarray=split/\n/,($telnet->waitfor('/]/'))[0];

Franco
: Online tools for structural design
: Magnetic brakes for fun rides
: Air bearing pads
 
prex's code is probably best for the second, since it is literal. But if you know that only one element is returned, that map would be functionally equivalent and easier to read:

Code:
[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]@newarray[/blue] = [url=http://perldoc.perl.org/functions/map.html][black][b]map[/b][/black][/url] [red]{[/red][url=http://perldoc.perl.org/functions/split.html][black][b]split[/b][/black][/url] [red]"[/red][purple][purple][b]\n[/b][/purple][/purple][red]"[/red][red]}[/red] [blue]$telnet[/blue]->[maroon]waitfor[/maroon][red]([/red][red]'[/red][purple]/]/[/purple][red]'[/red][red])[/red][red];[/red]
- Miller
 
Have you tried like the documentation of the Net::Telnet module shows:

($prematch, $match) = $obj->waitfor($matchop);



------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Never even noticed that before. I'll have to give it a try. Stars for ALL!!
[afro2]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
RTM Travis [hammer] [smile]

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top