Hello Monks,
I'm reading a file ans sub "," with "|" , then I'm trying to strip the last string $var7 to take only certain values out of the string and concatenate the string back and pint it to a file. It is giving some errors like " Global symbol "$n" requires special package" Here is my code. I'll appreciate any help.

#! perl -w use strict; #use File::Find; #use File::Copy cp; open(IN, '<c:/doclist.chr') or die "Couldn't open file, $!"; open(OUT, '>c:/doclist.txt') or die "Couldn't open file, $!"; ## print OUT join '|', split /,/ while <IN>; while(<IN>) { chomp; # Remove the newline my ($var1, $var2, $var3, $var4, $var5, $var6, $var7) = split /,/; my $string1 = $var7; substr($string1, 24) = "H:\"; my $string2 = substr($var7,25,2); my $string3 = substr($var7,-13); my $finstring = $string1.$string2.$string3; ## Find file in sub-directory # find(\&wanted, '', '/bar'); # sub wanted { ... } # find \&wanted, "./"; #sub wanted { # print "$File::Find::name ", (-s $File::Find::name); # print "\n"; #} ## Copy file to another directory # copy("file1","file2"); # copy("Copy.pm",\*STDOUT);' # move("/dev1/fileA","/dev2/fileB"); # $n = FileHandle->new("/a/file","r"); # cp($n,"x");' # print OUT $var1,"|",$var2,"|",$var3,"|",$var4,"|",$var5,"|",$var6, +"|",$finstring,"\n"; } exit; #sub get_line { # prompts for, reads, chomps, and returns a line of input #print $_[0]; #chomp(my $line = <STDIN>); #$line; #} # my $source = &get_line("Which source file? "); # open IN, # $source or die "Can't open '$source' for input: $!"; # my $dest = &get_line("what destination file? "); # die "Won't Overwrite Existing File" # if -e $dest; #optional safety test # open OUT, ">$dest" or die "Can't open '$dest' for output: $!"; # my $pattern = &get_line("What search pattern: "); # my $replace = &get_line("What replacement string: "); #while (<IN>) { # s/$pattern/$replace/g; # print OUT $_; #} ### ##foreach my $file (glob "*.old") { # my $newfile = $file; # $newfile =~ s/\.old$/ .new/; # if (-e $newfile) { # warn "can't rename $file to $newfile: $newfile exists\n"; # } elsif (rename $file, $newfile) { # ## success, do nothing # } else { # warn "rename $file to $newfile failed: $!\n"; # } #} ###

20030217 Edit by Corion: Added formatting


In reply to string stripping by skyler

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.