Simpler Navigation coming for Servers and Operating Systems
Coming soon: a much simpler Servers and Operating Systems section of the Community. We will combine many of the older boards, and you won't have to click through so many levels to get at the information you need. If you are looking for an older board and do not find it, check the consolidated boards, as the posts are still there.
Operating System - Microsoft
cancel
Showing results for 
Search instead for 
Did you mean: 

Perl - pattern matching

Fabrizio Maggioni_2
Super Advisor

Perl - pattern matching

Hi Support,

 

I have created a perl script that read a configuration file and extract from it one field if pattern match (field separator is ;;)

 

If i run it on HPUX/Linux host it works corretcly but if i try to run the script on Windows box it fails.

 

The perl version is for both environment v5.8.8.

 

Can you help me ?

 

Thanks.

Fabrizio

 

 

 

 

------------------------

 

#!/opt/OV/contrib/perl/bin/perl

#Set my variables

my $in_file = $ARGV[0];

#my $in_file = 'configuration_logfile_weblogic';
open my $in_fh, '<', $in_file or die "Could not open file $in_file: $!
+";

my $fqdn = `hostname`;

@hostname_short = split(/\./,$fqdn,2);

my $hostname = "@hostname_short[0]";

$hostname=~ tr/A-Z/a-z/;

while ( my $line = <$in_fh> ) {
        if($line =~ m/^$hostname;;(.*);;/) {
        print $1;
        }
}

close $in_fh  or die "Could not close file $in_file: $!";

 

 

P.S. This thread has been moved from HP-UX>Languages and Scripting to Microsoft > general. -HP Forum Moderator

2 REPLIES
Patrick Wallek
Honored Contributor

Re: Perl - pattern matching

>> ...if i try to run the script on Windows box it fails.

 

How does it fail?  What sort of error do you get?  

Fabrizio Maggioni_2
Super Advisor

Re: Perl - pattern matching

Hi,

 

It didn't print $1 .. but now with this change:

 

my ($hostname) = `hostname` =~ /([-a-zA-Z0-9]+)/;
$hostname=~ tr/A-Z/a-z/;

 

it works correctly !

 

Thanks,

Fabrizio