Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Setting Conditional Variable Based on Partial Match

by ccn (Vicar)
on Dec 19, 2008 at 19:41 UTC ( [id://731643]=note: print w/replies, xml ) Need Help??


in reply to Setting Conditional Variable Based on Partial Match

First of all: use  use strict; and use warnings;. That will save a lot of time for you.

It will be good to put backslash before * in regexp if you want to match an asterisk. (see perldoc perlre about metacharacters)

Yes $type must be declared outside of condition block. But rather before if clause than after it. And seems you want to use = instead of eq when assigning a value to $type

my $type = ($B1 =~ m/^\*/ or $B2 =~ m/^\*/) ? 'S' : 'I';

Replies are listed 'Best First'.
Re^2: Setting Conditional Variable Based on Partial Match
by Osiris1975 (Novice) on Dec 23, 2008 at 20:43 UTC
    Thanks for the response. I actually do use strict and warnings, I just left them out of the code that I pasted here. I'll include everything in my program in the future. The backslash tells perl to recognize the character "as is" and not as a special character, correct?
      > The backslash tells perl to recognize the character "as is" and not as a special character, correct?

      Yes with some exceptions:

          \t		tab             (HT, TAB)
          \n		newline         (NL)
          \r		return          (CR)
          \f		form feed       (FF)
          \b		backspace       (BS)
          \a		alarm (bell)    (BEL)
          \e		escape          (ESC)
          \033	octal char	(example: ESC)
          \x1b	hex char	(example: ESC)
          \x{263a}	wide hex char	(example: SMILEY)
          \c[		control char    (example: ESC)
          \N{name}	named Unicode character
      
      
          \l		lowercase next char
          \u		uppercase next char
          \L		lowercase till \E
          \U		uppercase till \E
          \E		end case modification
          \Q		quote non-word characters till \E
      

      see: perldoc perlop (Quote and Quote-like Operators)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://731643]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-23 13:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found