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!

$1 - can it be 'reset to null' ?

Status
Not open for further replies.

delinde

Programmer
Aug 29, 2012
1
0
0
DE
If you are doing RegEx work, and you want to be sure that $1 is null, you cannot do this:

$1 = "";     ## This will produce an error:  $1 is read only

But you can do this:

m/()()()/;     ## will reset $1, $2 and $3 to be nothing


HTH, delinde
 
Another approach, rather than checking to see if there is a value in $1, $2 and $3, could be to do something like:
Code:
if ($someVar =~ m/(.)(..)(...)/) {
    # execute this block if the regex succeeds
    # also means $1, $2 and $3 were set
} else {
    # regex did not match - execute this block
}
 
Hi there,

The sortest way to reset all $N variable is to call for a match like:
/.?/;
This will ever be successful and all the matching vars are reset.

BR,
Marcel

___
____
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top