Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Format Question

Status
Not open for further replies.

percent

IS-IT--Management
Apr 27, 2004
176
US
I am very new to perl - I am editing a script that outputs data on a linux machine:
below is what I think is the portion of the code I need help with - I need help in formating the $port variable
The $port variable is usually equal to S0 through S32 (it is equal to one of these usually)
What I need done is to make it so that if $port is equal to S0 through S9 to format it as S00 - S09 (I need to have the leading zero)

Code:
#code section I think is where the formating needs to be done
my ($port, $user, $start);
format STDOUT =
@<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<
$port, $user,   $start
.

I have code to do this with the linux command sed - but this is in linux and I'm not sure if it can be used with perl
Code:
#Linux command to format $port
$port=`echo "$port" |sed 's/S\([0-9]\)/S0\1/g;s/S0\([0-9][0-9]\)/S\1/g'

Any help will be appreciated

%, 2004
 
$port=ñ/S/; #remove the S, ignore the ñ I´m on a spanish keyboard and can´t find teh tilde
$port="S".sprintf("%0.2d",$port);

HTH
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ... smack the fecker
 
This did not work for me the code is below could you tell me if I mistyped it

Code:
my $skipok = 1;
foreach my $arg (@ARGV) {
  $skipok = 0 if $arg eq "-a";
$port=~//;
$port="S".sprintf("%0.2d",$port);
}

my ($port, $user, $start);
format STDOUT =
@<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<
$port,   $user,   $start
.

%, 2004
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top