I need help from the wizards of Perl,.. I'm trying to write a small script that goes to an ftp server and "gets" some job data files, ftping them to a directory on my unix box, to a directory named after the job number,.. I then want to grab all the files in my local directory , rename them according to their contents (i.e. name is parsed from the first line of the file) (unless its already name .*memo$ or .*seq <- these dont have the filename on the firstline), Then in another subroutine I split (like unix split) the files into groups of files 600 lines or less, i.e. ignore the files smaller than 600 lines,..(both working on my local directory) Now,..the ftp part works without a hitch,..The renamefile and splitter subroutines both work according to intention,.. BUT,..here's the rub,..I cant seem to get the script to work, if BOTH subroutines are called,... i.e. runs ok if either Renamefile or Splitter is commented out,... this is the error I get and this is the script, if I dont comment out 1 or the other subroutine,... (just the ip's and user/passwords are snipped but the ftp part works fine)
> ftptest.pl Enter the COEO :=> h9z238 splitter fail : No such file or directory at ./ftptest.pl line 91, <EX +TRACT1> chunk 39.
#!/usr/bin/perl -w use strict; use File::Path; use Getopt::Std; use lib "$ENV{HOME}/perllib"; use Net::FTP; my $username = "ftpuser"; my $password = "ftppass"; my $remdir = "/webdata/extracts/SWEST/"; my @remfiles; my $remfile; my $localdir = "$ENV{HOME}/hw_extracts/"; my $coeo; my $COEO; my $coeodir; # the directory where everything happens # main # print "Enter the COEO :=> "; chomp ($coeo = <STDIN>); $COEO = uc($coeo); $coeodir = $localdir . $COEO; if (chdir($coeodir)) { chdir($localdir); rmtree($COEO) ; mkdir($COEO, 0777); chdir($coeodir);} else { chdir($localdir); mkdir($COEO, 0777); chdir($coeodir)} $remdir .= $COEO; # # try some ftping here my $ftp = Net::FTP->new("XX.XX.XX.XX") or die "Cant connect: $@\n"; # +XX is just and example $ftp->login($username, $password); $ftp->cwd($remdir); @remfiles = $ftp->ls($remdir); foreach $remfile (@remfiles) { $ftp->get($remfile); } # it works so far up to here , changes dirs etc,... # &Renamefile($coeodir); &Splitter($coeodir); ##################################################### sub Renamefile { my $extract; my $newname; my @flist; my $tempdir = shift; opendir (COEODIR, $tempdir) or die "Can't opendir $tempdir: $!"; @flist = grep { $_ ne '.' and $_ ne '..' } readdir COEODIR ; foreach $extract (@flist) { if ( $extract =~ /^.*_memo/) { $newname = $coeo."_memo"; } elsif ( $extract =~ /^.*_seq/) { $newname = $coeo."_seqchart" +; } else { open ( EXTRACT,"< $extract") || die "renamefile fail: $! +"; my @lines = <EXTRACT> ; # slurp the file into array AND my $lines = $lines[0]; # get the newfilename from the f +irst line $lines =~ /TAB (.*?)$/; $newname = $coeo . "_" . lc($1); } # close EXTRACT; rename($extract, $newname) or warn "Cant rename $extract to $newname +, $!\n"; }#foreach }#sub ##################################################### sub Splitter { my $i=0; my @arraychunk; my $extract1; my @flist; my @temparray; my $tempdir = shift; opendir (COEODIR1, $tempdir) or die "Can't opendir $tempdir: $!"; @flist = grep { $_ ne '.' and $_ ne '..' } readdir COEODIR1 ; foreach $extract1 (@flist) { open ( EXTRACT1,"< $extract1") || die "splitter fail : $!"; ## t +his is where the error comes from @temparray = <EXTRACT1> ; if ( @temparray > 600 ) { print "$extract1\n"; while (@arraychunk = splice @temparray, 0, 600 ) { open (NEWFILE, "> $extract1"."_"."$i"); $i++; print NEWFILE @arraychunk;} #while } #if # close (EXTRACT1) ; # close (NEWFILE) ; } #foreach } #sub
Thanks BusterGonad

In reply to 2 Working Subroutines Conflict by bustergonad

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.