I was told that to create a routine that any program can use, I need to make a module, so I tried my hand at that. But for the life of my, I can't get it to work. Can anyone glance over my scripts to tell me what it is i'm doing wrong?
This is the script:
use strict; use warnings; my @file; my $file1; my $file2; print "Please enter the name of the file to copy.\n"; use FileNamePrep qw(&func1); open FILE, "<$file1"; while(<FILE>){ push @file, $_; } close FILE; print "\nPlease enter the name of the copy destination.\n"; use FileNamePrep qw(&func2); if($file2 eq "\n"){ $file2='C:\Documents and Settings\Copy Destination.txt'; print "\nIf you did not give a destination, your new file will be found under C:\ Documents and Settings, with the name Copy Destination.txt\n"; } open LOG, ">$file2"; print LOG @file; close LOG;
And here is my 'module':
package FileNamePrep; use strict; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 0.1; @ISA = qw(Exporter); @EXPORT = (); @EXPORT_OK = qw(func1 func2); %EXPORT_TAGS = ( DEFAULT => [qw(&func1)], Both => [qw(&func1 &func2)]); sub func1 { for(my $file1=<>){ chomp($file1); if(m/\"/){ chop($file1); $file1=reverse($file1); chop($file1); $file1=reverse($file1); } } } sub func2 { for(my $file2=<>){ chomp($file2); if(m/\"/){ chop($file2); $file2=reverse($file2); chop($file2); $file2=reverse($file2); } } } 1;
Thanks in advance.

In reply to Making/Using a module. by Andrew_Levenson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.