[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] REgular Expression for IP address



=Ronald wrote:
> On Sat, Feb 12, 2000 at 03:33:54PM +0100, Detlef Lindenthal wrote:
> > $IPN =~ s/\./x/g;
> > @IPN = split "x", $IPN;
> >     ## Sorry for these two lines -- but how could I have split at "."??
> >     ## This does not work:  @IPN = split ".", $1;
> >     ##      nor does this:  @IPN = split "\.", $1;

> The same way you change the periods to Xs.  The first argument to split is
> a _regular expression_.

> @IPN = split "\\.", $1;   # workable
> @IPN = split "\.", $1;    # also workable
> @IPN = split /\./, $1;    # PREFERRED
> @IPN = split "\.", $1;
> Ronald


Hi Ronald,

thank you for repairing. But I do not agree completely:
=cut

$_ = "asdf.asdf.asdf.asdf";
s;a;aa;g;   ## here even   ;   is allowed.
print "\n(1.) ", join " / ", split "\." , $_; ## not workable on my machine!!

print "\n(2.) ", join " / ", split '\.', $_;  ## works fine
print "\n(3.) ", join " / ", split "\\.", $_; ## works fine -- why??
print "\n(4.) ", join ' / ', split /\./, $_;  ## works fine
print "\n(5.) ", join " / ", split /\\./, $_; ## does not split
#print"\n(6.) ", join " / ", split |\.|, $_;  ## would yield a syntax error


=You  write:

> The first argument to split is a _regular expression_.

If so -- why can RE in this case be delimited by  "  ,
whereas in other cases   "  is not allowed? Are there different
classes of RE or classes of use of RE? -- If this topic is tooo special, then

forget my question. I am glad that my script works :-)

Detlef Lindenthal <detlef@lindenthal.com>











# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org