Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

subsitute s/ and match m/ failure

by kp2a (Sexton)
on Jan 22, 2009 at 14:53 UTC ( #738178=perlquestion: print w/ replies, xml ) Need Help??
kp2a has asked for the wisdom of the Perl Monks concerning the following question:

someone please point out error
#! /usr/bin/perl -w use strict; my $test = " v2.9.50"; my ($ip,$model) = split /:/,$test; $model =~ s/\.log$//; die if $model =~ /log/; print "<$ip> <$model>\n"; output [john@scan log]$ ./ <> <MikroTik v2.9.50> [john@scan log]$ perl -v This is perl, v5.8.8 built for i386-linux-thread-multi

I expected ".log" to be gone or die!

Update: sorry - obvious!

20090123 Janitored by Corion: Restored original content above the update

Comment on subsitute s/ and match m/ failure
Download Code
Replies are listed 'Best First'.
Re: subsitute s/ and match m/ failure
by svenXY (Deacon) on Jan 22, 2009 at 15:00 UTC
    since you split on ':' which is after .log,
    $ip =~ s/\.log$//;
    will do the trick.
Re: subsitute s/ and match m/ failure
by Bloodnok (Vicar) on Jan 22, 2009 at 15:29 UTC
    As clarification of what's been said elsewhere, you are testing the wrong element of the split ... to use your original code, change
    $model =~ s/\.log$//; die if $model =~ /log/;
    to read
    $ip =~ s/\.log$//; die if $ip =~ /log/;

    A user level that continues to overstate my experience :-))
Re: subsitute s/ and match m/ failure
by b10m (Vicar) on Jan 22, 2009 at 15:23 UTC

    You're trying to strip '.log' of $model, where clearly you want to strip it of $ip.

Re: subsitute s/ and match m/ failure
by matze77 (Friar) on Jan 22, 2009 at 16:35 UTC

    Hmm. What is obvious, i dont understand a word. Am I too silly? What is the failure? Or is there another context i might have missed?

    Thanks MH
      The OP replaced his original question with this meaningless reply to other replies. Hopefully the Janitors restore the original content.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://738178]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2015-11-25 20:35 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (690 votes), past polls