Re: Split not acting the way I want it to

2008-12-15 Thread Todd
Another fun way is to use `reverse' and `numeric/string conversion' as below. perl -le 'print 0+reverse int 0+reverse "1.2.3.45"' 45 Best regards, Todd -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: Split not acting the way I want it to

2008-12-10 Thread Chas. Owens
On Wed, Dec 10, 2008 at 18:32, Dr.Ruud <[EMAIL PROTECTED]> wrote: snip > $ perl -wle' > my $ip = v23.34.45.56; > print ord substr $ip, -1; > ' > 56 > > > $ perl -wle' > my $ip = "23.34.45.56"; > print ord substr eval "v$ip", -1; > ' > 56 snip I would have hoped perl would have thrown a warning

Re: Split not acting the way I want it to

2008-12-10 Thread Dr.Ruud
"John W. Krahn" schreef: > $ perl -le' > use Socket; > my $ipAddress = "23.34.45.56"; > print unpack "xxxC", inet_aton $ipAddress; > ' > 56 $ perl -wle' my $ip = v23.34.45.56; print ord substr $ip, -1; ' 56 $ perl -wle' my $ip = "23.34.45.56"; print ord substr eval "v$ip", -1; ' 56 :

Re: Split not acting the way I want it to

2008-12-10 Thread Paul Lalli
On Dec 9, 3:35 pm, [EMAIL PROTECTED] (David Shere) wrote: > Hello.  I'm not a new perl programmer, but I feel like one today.  I > want to pull the last octet off of an IP address and print it to > standard output.   Others already answered your actual split() question. So I'll just suggest an al

Re: Split not acting the way I want it to

2008-12-10 Thread David Shere
On Tue, 2008-12-09 at 18:26 -0800, John W. Krahn wrote: > David Shere wrote: > > > > prints nothing. split() *does* return an array, right? > > No, funtions and subroutines return lists. Yeah, and that's why I feel like a beginner today. I've been operating for a while as if functions return a

Re: Split not acting the way I want it to

2008-12-09 Thread Rob Dixon
Mr. Shawn H. Corey wrote: > Rob Dixon wrote: >> Mr. Shawn H. Corey wrote: >>> >>> print '', (split( /\./, $ipAddress ))[-1]; >> >> Ugly, ugly, ugly. > > OK, try: > > print substr($ipAddress,rindex($ipAddress,'.')+1); Are you really saying that you could make it even worse if you wanted to? Rob

Re: Split not acting the way I want it to

2008-12-09 Thread John W. Krahn
Mr. Shawn H. Corey wrote: On Wed, 2008-12-10 at 03:04 +, Rob Dixon wrote: Mr. Shawn H. Corey wrote: print '', (split( /\./, $ipAddress ))[-1]; Ugly, ugly, ugly. OK, try: print substr($ipAddress,rindex($ipAddress,'.')+1); $ perl -le' use Socket; my $ipAddress = "23.34.45.56"; print unp

Re: Split not acting the way I want it to

2008-12-09 Thread John W. Krahn
Mr. Shawn H. Corey wrote: On Wed, 2008-12-10 at 03:04 +, Rob Dixon wrote: Mr. Shawn H. Corey wrote: print '', (split( /\./, $ipAddress ))[-1]; Ugly, ugly, ugly. OK, try: print substr($ipAddress,rindex($ipAddress,'.')+1); $ perl -le' my $ipAddress = "23.34.45.56"; print $ipAddress =~ /

Re: Split not acting the way I want it to

2008-12-09 Thread Mr. Shawn H. Corey
On Tue, 2008-12-09 at 22:20 -0500, Mr. Shawn H. Corey wrote: > On Wed, 2008-12-10 at 03:04 +, Rob Dixon wrote: > > Mr. Shawn H. Corey wrote: > > > > > > print '', (split( /\./, $ipAddress ))[-1]; > > > > Ugly, ugly, ugly. > > > OK, try: > > print substr($ipAddress,rindex($ipAddress,'.')+1);

Re: Split not acting the way I want it to

2008-12-09 Thread Mr. Shawn H. Corey
On Wed, 2008-12-10 at 03:04 +, Rob Dixon wrote: > Mr. Shawn H. Corey wrote: > > > > print '', (split( /\./, $ipAddress ))[-1]; > > Ugly, ugly, ugly. > OK, try: print substr($ipAddress,rindex($ipAddress,'.')+1); -- Just my 0.0002 million dollars worth, Shawn The key to success is be

Re: Split not acting the way I want it to

2008-12-09 Thread Rob Dixon
Mr. Shawn H. Corey wrote: > > print '', (split( /\./, $ipAddress ))[-1]; Ugly, ugly, ugly. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Split not acting the way I want it to

2008-12-09 Thread John W. Krahn
David Shere wrote: Hello. Hello, I'm not a new perl programmer, but I feel like one today. I want to pull the last octet off of an IP address and print it to standard output. I have this so far: @octets = split(/\./, $ipAddress); print pop(@octets); Which works great. I have no oth

Re: Split not acting the way I want it to

2008-12-09 Thread Chas. Owens
On Tue, Dec 9, 2008 at 16:04, Mr. Shawn H. Corey <[EMAIL PROTECTED]> wrote: > On Tue, 2008-12-09 at 15:55 -0500, David Shere wrote: >> On Tue, 2008-12-09 at 15:51 -0500, Mr. Shawn H. Corey wrote: >> > print '', (split( /\./, $ipAddress ))[-1]; >> >> Thanks. I was searching for about an hour before

Re: Split not acting the way I want it to

2008-12-09 Thread Mr. Shawn H. Corey
On Tue, 2008-12-09 at 15:55 -0500, David Shere wrote: > On Tue, 2008-12-09 at 15:51 -0500, Mr. Shawn H. Corey wrote: > > print '', (split( /\./, $ipAddress ))[-1]; > > Thanks. I was searching for about an hour before I posted here; I found > an answer online a few minutes later: > > http://www.p

Re: Split not acting the way I want it to

2008-12-09 Thread David Shere
On Tue, 2008-12-09 at 15:51 -0500, Mr. Shawn H. Corey wrote: > print '', (split( /\./, $ipAddress ))[-1]; Thanks. I was searching for about an hour before I posted here; I found an answer online a few minutes later: http://www.perlmonks.org/?node_id=299283 Curious: What's the '', for? Scalar

Re: Split not acting the way I want it to

2008-12-09 Thread Mr. Shawn H. Corey
On Tue, 2008-12-09 at 15:35 -0500, David Shere wrote: > Hello. I'm not a new perl programmer, but I feel like one today. I > want to pull the last octet off of an IP address and print it to > standard output. I have this so far: > >@octets = split(/\./, $ipAddress); >print pop(@octets);

Split not acting the way I want it to

2008-12-09 Thread David Shere
Hello. I'm not a new perl programmer, but I feel like one today. I want to pull the last octet off of an IP address and print it to standard output. I have this so far: @octets = split(/\./, $ipAddress); print pop(@octets); Which works great. I have no other use for @octets, so I should