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

How to understand this piece of perl code? 1

Status
Not open for further replies.

lcs01

Programmer
Joined
Aug 2, 2006
Messages
182
Location
US
Below is a piece of perl code I need help to understand:

Code:
my $command = "process$fieldType($locked,$req,$colID,$colspan,$rowspan,$maxWidth,$maxHeight,'$fieldName','$sectable','$nameField','$idField',$caseAware,'$linkTable',$activeCase,$ai,$large,\\\@jsver,\\\$jsSetupCode)";   
$command =~ /(.*)/;
my $tempthingy = eval($1);
warn "\$1 = $1\n\$command = $command\n\n";

The output from 'warn' is:

Code:
[Tue May 15 16:41:27 2007] null: $1 = processMultipleDropdown(0,1,99591,1,1,25,8,'c99591','Discovery.2509SECt1440c99591', 'valueField','id',0,'Discovery.2509LINKt1440c99591',2509,0,0,\@jsver,\$jsSetupCode)
[Tue May 15 16:41:27 2007] null: $command = processMultipleDropdown(0,1,99591,1,1,25,8,'c99591','Discovery.2509SECt1440c99591','valueField','id',0,'Discovery.2509LINKt1440c99591',2509,0,0,\@jsver,\$jsSetupCode)

What I don't understand:

1) What is this: $command =~ /(.*)/;
2) The difference between $command and $1?

Thank you for your help!
 
There is no difference between $command and $1 in the code you posted.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Are you saying $command and $1 are the SAME? What about '$command =~ /(.*)/;' then?

Thanks.
 
Kevin, I guess that I was one second slower than you. :)

What is this for then?

$command =~ /(.*)/;
 
Code:
$command =~ /(.*)/;
That's a regular expression, using $command as string to match against.

This:
Code:
/(.*)/;

is the same thing, but operating on the $_ scalar.

$1 is the first 'captured' expression from the regular expression. Captures are the expressions surrounded by parentheses. The '.*' expression is captured to $1.

.* matches any number of non-newline characters, so...

the difference between $command and $1 is that $1 will only contain characters up to but not including the first newline character in $command.
 
Thank you, brigmar.

Now I understand it.

Code:
  my $command = "process$fieldType($locked,$req,$colID, [b]\n[/b] $colspan,$rowspan,$maxWidth,$maxHeight,'$fieldName','$sectable','$nameField','$idField',$caseAware,'$linkTable',$activeCase,$ai,$large,\\\@jsver,\\\$jsSetupCode)";
  $command =~ /(.*)/;
warn "\$1 = $1\n\$command = $command\n\n";

The out put:

Code:
[Tue May 15 17:08:28 2007] null: $1 = processPDPeopleList(1,0,97368,
[Tue May 15 17:08:28 2007] null: $command = processPDPeopleList(1,0,97368,
[Tue May 15 17:08:28 2007] null:  1,1,25, 3,'author','Discovery.2509People_1','valueField','id',0,'Discovery.2509LINKt1440c97368',2509,1,1,\@jsver,\$jsSetupCode)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top