On 6/27/07, Amichai Teumim <[EMAIL PROTECTED]> wrote:
If I use the regular expression with the grep command in terminal I get only the IPs. Here in Perl I don't get any output.
The grep command uses grep's regular expressions, but Perl uses Perl's regular expressions. Alas, everybody's regular expressions are different. Perl's are usually better, of course. But the syntax is always different.
@input = `cat ~/ip.txt`;
I hope that this is _supposed_ to be a quick-and-dirty program. This works, although it's slower than using a filehandle would be, and it probably uses more memory. Although if you're using the tilde to open a file in the user's home directory, well, that's maybe the best way to do it.
/[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}/){
I think in Perl that pattern might be this: /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/ But do you really want to match 999.999.999.999? You don't have to. Have you heard of Regexp::Common? Regexp::Common::net seems to have what you want. /^$RE{net}{IPv4}$/ http://search.cpan.org/~abigail/Regexp-Common-2.120/lib/Regexp/Common.pm http://search.cpan.org/dist/Regexp-Common/lib/Regexp/Common/net.pm Even if you don't want to install the module to get just one pattern, you could use the pattern that it supplies, which is sure to be at least as good as anything you would write on your own. Good luck with it! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/