Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Appending two files

by abcdefg (Acolyte)
on May 17, 2012 at 20:32 UTC ( #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 line 14. Global symbol "$usage" requires explicit package name at line 26. Global symbol "$result" requires explicit package name at 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.


    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?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2023-03-23 08:47 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.