Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Appending two files

by abcdefg (Acolyte)
on May 17, 2012 at 20:32 UTC ( [id://971168]=perlquestion: print w/replies, xml ) Need Help??

abcdefg has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to append two files in a single file using command line arguments but I am getting many errors like Global symbol "$usage" requires explicit package name at add.pl line 14. Global symbol "$usage" requires explicit package name at add.pl line 26. Global symbol "$result" requires explicit package name at add.pl line 32.

#!/usr/bin/perl use strict; use warnings; use File::Basename; $| = 1; my $scriptname = fileparse(__FILE__); my $t; my $imgfile; my $hash_filename; my $Signed_filename my $usage = " Usage: $scriptname (-i <file1> -t <file2> -o <Output_file> ) ** Image Types ** -i <file1> : Required: -t <file2> : Required.Inout file to read the unsigned file -o <Output_file> : Required. Output file to write the sig +ned input file "; if ($#ARGV == -1) # if user enters no arguments, exit with the usage i +nstructions { die $usage; } # Get the command line options passed to us $result = GetOptions ("File1=s" => \$file1, "File2=s" => \$file2, "out=s" => \$Output_file); open(FH,">$Output_file") or die "$!\n"; print FH $file1,"\n" ; print FH $file2,"\n" ; close FH;

What am I doing wrong?

Replies are listed 'Best First'.
Re: Appending two files
by CountZero (Bishop) on May 17, 2012 at 22:26 UTC
    You forgot to end line 12 with a semi-colon.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
Re: Appending two files
by Anonymous Monk on May 17, 2012 at 20:49 UTC
Re: Appending two files
by Marshall (Canon) on May 17, 2012 at 20:39 UTC
    Well, the messages pretty much speak for themselves. $scriptname is used in your $usage variable, but never declared. Nowhere do you use the value of $result that you get from GetOptions. I would also go ahead and "use strict;".
Re: Appending two files
by ww (Archbishop) on May 17, 2012 at 22:40 UTC
    It's no part of your code mistakes... but your language needs correction (or, "invited pedantry" if you don't care about being clear and accurate).

    You're trying to 'concatenate' two files; not "append" them. You might append a second file to the first (result: two files, the first of which contains the original contents of both), but what you're trying to do is create a third file from the first two.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://971168]
Approved by sundialsvc4
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-24 21:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found