Dizzy74 wrote:
> 
> Hi All

Hello,

>     Today I was trying to do some work with perl and needed to use  a
> function that would trim leading or trailing spaces from a string.

perldoc -q "blank space"

Found in /usr/lib/perl5/5.6.0/pod/perlfaq4.pod
       How do I strip blank space from the beginning/end of a
       string?


> Looked on the web

The Perl documentation should have been installed on your hard disk when
you installed Perl.


> and found basicaly perl uses either chop or chomp each
> with their own features.

chop() removes the last character of a string _whatever it may be_,
chomp() removes the value of $/ (which is set to "\n" by default) from
the end of a string.


> When I tried to apply it to my $var it either returned zeros or blanks.
> Finally I found what looks to be a regular expression replacement which
> does what  I want it to, but I would never think it (trimming) to be so
> tricky. I though it was supposed to be "easy things easy..." <grin>
> 
> open(FILE,"F:\\test_db\\Admin\\MINIHI\\DEF\\prog_list.txt"|| die "cant open file") ;

You have a precedence problem with the || operator, either parenthesize
correctly or use the or operator.  Perl allows you to use slashes
instead of backslashes as path separators.  You should include the $!
variable in the error message so that you know _why_ the open failed.

my $file = 'F:/test_db/Admin/MINIHI/DEF/prog_list.txt';
Either:
open( FILE, $file ) || die "cant open $file: $!";
Or:
open FILE, $file or die "cant open $file: $!";


> chomp(@tblname = <FILE>);
> open (outfile, ">F:\\test_db\\Admin\\MINIHI\\DEF\\INSERTprog_list.sql"||
> die "cant open file") ;

Same as above.


>     foreach $progid (@tblname) {
> 
>         $progid =~ s/\s+$//;

This should work unless there are non-whitespace characters at the end
of the string.  The \s character class includes the characters " ",
"\n", "\r", "\t", and "\f".


>         print outfile  ("insert into ... where program_id = '$progid'
> and rownum <=300 ;\n") ;
>         print "insert into ... where program_id = '$progid' and rownum
> <=300 ;\n" ;
> 
>         }
> close outfile ;
> 
> #### prog_list.txt example
> 
> name -space-space
> name_address -tab-space
> name_phone - somekind of whitespace



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to