Operating System - HP-UX
1835110 Members
2179 Online
110076 Solutions
New Discussion

Re: cant cut 4 char for file name in perl

 
SOLVED
Go to solution
Ratzie
Super Advisor

cant cut 4 char for file name in perl

We are at it again...
I can cut the first for charecters on from stndin in but I still need the full sntdin.

I want to call the file created with the first 4 char.

print "Enter BLD >";
chomp (my $bld = );
length ($bld) > 4 and $bld=substr$bld,0,4;
**************

## this give me the first 4 char. But I need to save this to another variable to use for file nameing. I still need the full data enter.
It puts the data into the file like
204xxxx013,EAST,ROOM2,00 0 02 30,CUSTOMER HAS

I need it to look like what I originally type which was:
204xxxx013,EASTBUILDING,ROOM2,00 0 02 30,CUSTOMER HAS

***********
print "Enter room>";
chomp (my $room = );

open my $fc, ">fileC" or die "fileC: $!";
open my $ft, ">fileT" or die "fileT: $!";
open my $fo, ">fileO" or die "fileO: $!";

while (<>) {
chomp; # Will remove the leading , or new line
my @a = split /,/, $_, -1;
my $f = /TELN/ ? $ft : /CUST/? $fc : $fo;
print $f join "," => $acode.$a[0], $bld, $room, $a[1], $a[2], "\n";
...
2 REPLIES 2
Rodney Hills
Honored Contributor
Solution

Re: cant cut 4 char for file name in perl

Then take this line-
length ($bld) > 4 and $bld=substr$bld,0,4;

and change it to-
length ($bld) > 4 and $bld4=substr$bld,0,4;

Use $bld4 for your 4 character and $bld is left alone.

HTH

-- Rod Hills
There be dragons...
Rodney Hills
Honored Contributor

Re: cant cut 4 char for file name in perl

Forget my last suggestion. Just change it to-
$bld4=substr$bld,0,4;

Their is no need to test if it's >4 since substr will still do the right thing...

-- Rod Hills
There be dragons...