or just:
my $filename="/home/dbsmith/passwd.duby02.linux";
my ($pass,$hostname,$platform)=split /\./, $filename;

~i


On 12/12/06, Lawrence Statton XE2/N1GAK <[EMAIL PROTECTED]> wrote:


If you're dealing with variable length strings, separated by some kind
of character, then regexp is the tool you want, not substr.

This snippet will work so long as hostname and platformname are made
up of \w ... if not, substitute in an appropriate character class.

#!/usr/bin/perl
use strict;
use warnings;

foreach my $filename (qw (
                           /home/dbsmith/passwd.dubhpr01.sun
                           /some/other/path/passwd.fizzbox.hpux
                           /yet/another/path/passwd.gronko.aix
                           /still/more/paths/to/passwd.foohost.linux
                        )
                     ) {
  my ($hostname, $platform) = $filename =~ m|\.(\w+)\.(\w+)$|;
  print "Hostname: $hostname, Platform: $platform\n";
}


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Reply via email to