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/
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
"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
:
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
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
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
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
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 =~ /
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);
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
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/
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
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
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
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
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);
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
17 matches
Mail list logo