LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-22-2002, 07:15 AM   #1
bobjones
LQ Newbie
 
Registered: Jun 2002
Location: Houston, Texas (U.S.)
Distribution: mandrake 7.0, redhat 6.2, 7.0, 7.1, 7.2
Posts: 6

Rep: Reputation: 0
Smile perl split(@array)?? wtf?


hmm, well, i need to pass an IP address, and return it as ip.ip.ip.1 instead of ip.ip.ip.ip.

I have been trying to use a mean split /./, $ip_addr but i have no idea what im doing..... 3 books later, no progress. god im a loser... any ideas on how to take $ip_addr (123.100.101.85) and make print 123.100.101.1??? also, i just cant understand how to call elements of @ arrays... if i could, i feel that i might have a chance...

thanx in advance!!
 
Old 09-22-2002, 08:02 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
$IPADDR=~s/\d+$/1/

i think. i.e. replace the last lump of digits with a one.
 
Old 09-22-2002, 08:03 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
*might* want a g at the end.

might i ask what you're actaully DOING with these books? sitting on them? I really can't see how you should have any trouble with questinos like these with even the poorest perl book...

calling array elements?

element 1 = $array[0]
element 0 = $array[1]
etc...

is that all you meant?

Last edited by acid_kewpie; 09-22-2002 at 08:05 AM.
 
Old 09-23-2002, 12:09 AM   #4
buster
LQ Newbie
 
Registered: Sep 2002
Posts: 9

Rep: Reputation: 0
try:

split(@ipSplit, $ip);

foreach $i (@ipSplit)
{
print $i, "\n";
# and so on.....
}


or

split(@ipSplit, $ip);

ip[3] = 1;


or

$ip =~ s/^(\d+\.\d+\.\d+\.)\d+/$1\1/; # hm... i hope this works
 
Old 09-23-2002, 12:11 AM   #5
buster
LQ Newbie
 
Registered: Sep 2002
Posts: 9

Rep: Reputation: 0
argh!

i mean @ipSplit = split(/\./, $ip);

not push(); ...
 
Old 09-23-2002, 10:41 AM   #6
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
acid_kewpie's first reply will work well. Although a split would work, there's really not alot of need for a split, since it's really a simple substitution that you're looking for.

I would personally prolly do it something like:
Code:
$ip_addr =~ s/\.\d{1,3}$/\.1/;
That way, not only is it looking for specifically 1 to 3 digits, but it's also making sure that the seperator . is there.

A split could be accomplished as:
Code:
$ipaddr = join(".", (split(/\./, $ipaddr))[0,1,2]) . ".1";
Either way, I don't think the interpreter is doing any more work.. so, just whatever you feel comfortable with. (=

TLD
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash shell script split array robertngo Programming 13 06-20-2011 12:01 AM
split command in perl not splitting / linuxmandrake Programming 1 11-03-2005 04:28 PM
PERL: Size of an array of an Array inspleak Programming 2 03-10-2004 03:24 PM
Perl Help (possible split) fooforon Programming 2 02-19-2004 06:53 AM
PERL: split on html tag? ocularbob Programming 12 09-08-2003 06:52 PM


All times are GMT -5. The time now is 03:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration