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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable Format

Status
Not open for further replies.

pani765

Programmer
Aug 14, 2003
12
US
Hello,

I am new to perl. So i was wondering if anyone can tell what the following line mean.


$event_id =~ /^(\d+)(_\d)?(\d*)$/o;
$event_id = "$1$2$3";

if i want event_id to in the format of $id_0_$i where i is 0 to x, how would i change those line.

Thank You,

Roj
 
$event_id =~ /^(\d+)(_\d)?(\d*)$/o;

/ start of pattern match
^ caret - match at beginning of line
( in this case, as it is soon to be followed by ), means store result... as $1
\d+ match at least one digit (\d = digit, + = at least one)
(_\d)? an underscore, a digit, report match (?) whether found or not, store as $2 (parentheses)
(\d*) match zero or more digits, store result as $3
$ match end of line
/ end of pattern match
0 compiles the pattern only once (will speed it up)

-----------------------------------------------------
$event_id = "$1$2$3";

assign $event_id to the stored matches as mentioned above - in the order match1 + match2 + match3

I'll have a think about the second part of your question

Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top