$num = 2001090701;
if ($num =~ /(\d{8})(\d{2})/) {
$fday = $1; $incr = $2;
print "fday = $fday \t incr = $incr \n";
} else {
print "$num is not in correct format\n";
}
The regular expression /(\d{8})(\d{2})/ looks for 8 digits followed by 2
digits and stores the results (due to the parens) in $1 and $2.
/\/\ark
-----Original Message-----
From: HURT, CHRIS [Non-Pharmacia/1000] [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 08, 2002 9:29 AM
To: '[EMAIL PROTECTED]'
Subject: Perl variable - cuts
Importance: High
Hi all;
Got a newbie question for you. I have a number of exactly 10 digits
(2001090701) and I want to be able to read it from a file, cut the first 8
digits from the last two digits and put each into a variable (for comparison
and addition). I would do it in the korn shell like this:
NUM=`grep Serial FILE | awk '{print $1}'`
TODAY=`date '+%Y%m%d'`
FDAY=`echo $NUM | cut -c 1-8`
typeset -Z2 INCR
INCR=`echo $NUM | cut -c 9-10`
if [ $FDAY -ne $TODAY ]; then
SNUM="${TODAY}01"
else
let INCR="$INCR + 1"
SNUM="${TODAY}${INCR}"
fi
print " $SNUM ;Serial" >> NEWFILE
However, I need to insert this logic into an existing perl script and am
only vaguely familiar with Perl (I can figure out what they do - but do most
of my programming in sh or ksh)
Thanks so much,
Chris
P.S. Please respond to my email address.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]