For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > April 2004 > Replace ' ???









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Replace ' ???
Lonewolf

2004-04-27, 12:07 pm

I have a function and can't seem to get this figured out. I have
apostrohe's in the file that I am pulling down, however I need to remove all
of the apostrophe's from the file before putting the file into the system.

<CODE SNIPPET>
$fields[0] =~ s/'//;
<END CODE SNIPPET>

The apostrophe character just needs to be removed and the field shrunk, so I
know it is something simple.

TIA!

Robert
William M West

2004-04-27, 12:07 pm

>
>I have a function and can't seem to get this figured out. I have
>apostrohe's in the file that I am pulling down, however I need to remove
>all
>of the apostrophe's from the file before putting the file into the system.



1. I'm not sure if ' has to be escaped when in a regex... so
try one the following:

s/'//g #get rid of all ' from the line

or
s/'//g #same as above, but using the \ to escape the ' just in case the '
#does some funny things in a regular expression.

willy

:)
James Edward Gray II

2004-04-27, 12:07 pm

On Apr 27, 2004, at 8:23 AM, LoneWolf wrote:

> I have a function and can't seem to get this figured out. I have
> apostrohe's in the file that I am pulling down, however I need to
> remove all
> of the apostrophe's from the file before putting the file into the
> system.
>
> <CODE SNIPPET>
> $fields[0] =~ s/'//;
> <END CODE SNIPPET>
>
> The apostrophe character just needs to be removed and the field
> shrunk, so I
> know it is something simple.


Did you forget a /g at the end of that regex?

$fields[0] =~ s/'//g;

James

John W. Krahn

2004-04-27, 3:41 pm

Lonewolf wrote:
>
> I have a function and can't seem to get this figured out. I have
> apostrohe's in the file that I am pulling down, however I need to remove all
> of the apostrophe's from the file before putting the file into the system.
>
> <CODE SNIPPET>
> $fields[0] =~ s/'//;
> <END CODE SNIPPET>
>
> The apostrophe character just needs to be removed and the field shrunk, so I
> know it is something simple.


Change

s/'//;

to

tr/'//d;



John
--
use Perl;
program
fulfillment
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com