sidney04 has asked for the wisdom of the Perl Monks concerning the following question:

Hi again :) I hope I'm not anoying anybody when I post really stupid questions :) I don't want to get RTFM ;)

Anyway, I tried to search the perldoc and also surf the web thinking I might find the answer to my question. Unfortunately I did not get any :(

I've been looking at this line of code which I really do not understand what the "&!" does, below is the line of code: if($key =~ /^PERIODEND/ &! $budgetdata) {BudgetGroup->budget($input, $myclass, 3)}

I understand the rest of this line except for the "&!". I will really appreciate any help ;)

Retitled by davido from 'Newbie Help :)'.

Replies are listed 'Best First'.
Re: What does &! mean?
by gam3 (Curate) on Jul 11, 2005 at 17:12 UTC
    First I think that this is a typo. It should read:
    if ($key =~ /^PERIODEND/ && !$budgetdata) { BudgetGroup->budget($input, $myclass, 3) }
    But this code does work.
    my $key = "PERIODEND"; my $budgetdata = 0; print $key =~ /^PERIODEND/, "\n"; print $budgetdata, "\n"; if ($key =~ /^PERIODEND/ & !$budgetdata) { BudgetGroup->budget($input, $myclass, 3) }
    So this would be true as 1 bitwise and 1 = 1.

    -- gam3
    A picture is worth a thousand words, but takes 200K.
Re: What does &! mean?
by thekestrel (Friar) on Jul 11, 2005 at 17:19 UTC
    Hi Sydney04,
    The &! is not that clear but is saying that you also need a second condition that is not true. A better way of writing it is...(see note below, depending on whether you are wanting two conditions or do a logical operation).
    if ( (condition1) && (!condition2) ) { }
    so in your case you want $key to begin with "PERIOD_END" and you want $budget data not to be set.
    Try runing the following and commenting and uncommeting the line that defines $budgetdata.. then rewrite it to the if statement I did above if you like...
    #!/usr/bin/perl my $key = "PERIODEND TODAY"; #my $budgetdata = "lots of numbers"; print "Hello\n"; if ( $key =~ /^PERIODEND/ &! $budgetdata) { print "Got here\n"; } else { print "Sorry =(\n"; }

    Update: I forgot to specify that I used '&&' instead of '&', with the difference being that the '&' is a bitwise operator that will do a NOT AND or NAND with the first condition as opposed to '&&' that requires two both condition 1 and condition 2. I was just splitting it.. that was to simplify...As gam3 points out though, the format of the if is probably supposed to be of format mentioned as bit twiddling on strings is not all that common, they are more likely just checking that you just don't have the budget data.


    Regards Paul
Re: What does &! mean?
by fmerges (Chaplain) on Jul 11, 2005 at 17:20 UTC

    Hi,

    Seems like he is putting together two operand...

    Try to change the ! for 'not', if nothing changes it really says:

    if(($key =~ /^PERIODEND/) & (not $budgetdata)){ BudgetGroup->budget($input, $myclass, 3) }

    So the single '&' is the Bitwise operand.

    Regards,

    |fire| at irc.freenode.net I like merlyn's disclaimer