- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Learning PERL
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2009 01:50 AM
02-13-2009 01:50 AM
Learning PERL
The script is to replace a certain pattern by opening given files of a particular type ( here .html files) #!/usr/bin/perl
use strict;
use warnings;
if ( @ARGV != 3 )
{
print("Arguments not sufficient\n");
exit(1);
}
my $oldname = shift(@ARGV);
my $newname = shift(@ARGV);
$filemaname = shift(@ARGV);
my @readlist;
if ( $filename = ~/\*/)
{
my @filelist= <*.html>;
foreach my $file (@filelist)
{
open(my $in, '<',$file )|| die ("Cannot open $file : $!") ;
while (<$in>)
{
push(@readlist,$_);
}
close($in);
open(my $out,">",$file);
foreach my $change(@readlist)
{
my $a =~ s/$oldname/$newname/g;
print( $out $a);
}
close($out);
}
}
exit(0);
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2009 02:18 AM
02-13-2009 02:18 AM
Re: Learning PERL
just a my before your line :
$filemaname = shift(@ARGV);
like this :
my $filemaname = shift(@ARGV);
Hope this helps
Kenavo.
Pat.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2009 05:02 AM
02-13-2009 05:02 AM
Re: Learning PERL
The 'strict' pragma is doing exactly what it should do.
You haven't identified the package in which '$filemaname' occurs, nor for that matter '$filename'.
You have a typographical error. Change:
$filemaname = shift(@ARGV);
...to:
my $filename = shift(@ARGV);
...and you syntax errors will vanish.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2009 08:24 PM
02-15-2009 08:24 PM
Re: Learning PERL
1) Drop the: if ( @ARGV != 3 )... bit
Instead use:
:
my $filename = shift or die "Missing filename argument";
and uh... in the output loop you probably mean:
foreach my $change(@readlist)
{
$change =~ s/$oldname/$newname/g;
print( $out $change);
}
Personally I would not bother with the @readlist, unless there is more to do.
I would just make in and out loop happen at the same time:
open in
open out
foreach in
{
substitute
print out
}
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2009 01:31 AM
02-16-2009 01:31 AM
Re: Learning PERL
http://perldoc.perl.org/diagnostics.html