?
Solved

/ operator

Posted on 2001-08-23
18
Medium Priority
?
244 Views
Last Modified: 2006-11-17
What does / do in PERL?

Where can I find more info on / online?

Thanks!
0
Comment
Question by:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 3
  • 2
  • +3
18 Comments
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 6418317
For example:

/^

/e

/ee

/\

etc.

etc.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6419675
man perlop
man perlre
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 6419728
...huh???
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:bebonham
ID: 6419818
or for the unix impared,

http://www.perldoc.com/perl5.6/pod/perlop.html

I think they typically use / for division.
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 6419852
/ is not used for division in the contect I am thinking of, I don't think...

Yes, I am unix-impaired  :)
0
 
LVL 6

Expert Comment

by:holli
ID: 6420105
could you please provide some code snippets. just to let us see the context.
the char / can have many meanings.

(quote char, regexp separator, special var ($/) ...)

0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 6420247
I think regex separator and special var is where I am headed with this.

I will find some code snippets, but I'm out of time today...I'll paste them in tomorrow...
0
 

Expert Comment

by:red5
ID: 6420356
a couple simple regex examples:

here we see if the variable (called scalar in perl) $variable contains "THIS TEXT"

if ( $var =~ /THIS TEXT/ ) {
  # yes it does
}

say you didn't know how many spaces were between THIS and TEXT.  you could:

if ( $var =~ /THIS\s+TEXT/ ) {
  # yes it does
}

\s means any whitespace character (space, tab, carriage return).  \s+ means 1 or more whitespace characters, so that would match:

THIS TEXT
THIS  TEXT
THIS <tab> TEXT

does this help?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6420773
what was wrong with my suggestion?
It prints out online (on UNIX) what you want.
If you mean that "online" is always connected to the internet then use:
   http://www.perldoc.com/perl5.6/pod/perlop.html
   http://www.perldoc.com/perl5.6/pod/perlre.html
or even
   http://www.perldoc.com/perl5.6/pod/
as bebonham suggested
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 6422212
ahoffmann:

I never said there was anything wrong with your suggestion.  I am still deciding which answer I like best.

red5 has given what look like some pretty good examples.

I need to go check your links, ahoofmann, and evaluate if they provide the answer I need.

Thanks,

Tom
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 6422213
I am strictly Win32, btw.

Unix specific examples won't work properly.
0
 
LVL 16

Expert Comment

by:maneshr
ID: 6423164
knowlton,

"...What does / do in PERL?

Where can I find more info on / online?..."

Can you please provide more detail on the context in which you are using /  ?
E.g. any code snippet that has the / about which you need more info etc..

That will help you get a more accurate answer, faster.

Let me know.
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 6423376
Okay:

@names=('Mrs Smith','Mr Jones','Ms Samuel','Dr Jansen','Sir Philip');

foreach $person (@names) {
     print "$person\n";
     last if $person=~/Dr /;


THe /Dr  /; part....what is the / doing?

What is /   in Perl?
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 6423382
OR this:

$_='HTML <I>munging</I> time !.';

/<I>(.*)<\/I>/i;

print "Found it ! $1\n";
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6423403
in those two cases, they are only used as delimiters for regular expressions.

the '/' before the I in both examples is literal.
in the regexp, it is escaped because '/' is also used as the delimiter.
0
 
LVL 16

Accepted Solution

by:
maneshr earned 60 total points
ID: 6423405
knowlton,

"...THe /Dr  /; part....what is the / doing?..."

In this case the / is used as a quote characters with the  pattern matching operator m

 last if $person=~/Dr /;

In simple terms the above line of code says if the variable $person contains the string Dr followed by a space character, exit out of the for loop.

you can also write the above statement as...

 last if $person=~ m/Dr /;

## NOTE:  the m may be omitted if the delimiters you pick are in fact slashes

Alternately, you can use ANY quote character.

E.g.

 last if $person=~ m'Dr ';
## NOTE: i have used ' instead of /


Again this is the same case in the 2nd example, wher you are searching the $_ special variable for
the string mentioned inside / /

NOTE: since you have added i at the end, the pattern match is case insensitive.
So the <I> can be <i> or <I> etc...

Hope that clarifies things.
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 6423418
Thank you, everyone.
0
 
LVL 16

Expert Comment

by:maneshr
ID: 6423606
knowlton,

You're welcome.

Glad to know you got the solution you were looking for.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question