Solved

/ operator

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

Where can I find more info on / online?

Thanks!
0
Comment
Question by:knowlton
  • 9
  • 3
  • 2
  • +3
18 Comments
 
LVL 5

Author Comment

by: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:knowlton
ID: 6419728
...huh???
0
 
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: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: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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Author Comment

by: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: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: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: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 15 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: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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now