CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Opposite of Chop?

 



andy7t
User

Dec 16, 2003, 9:46 AM

Post #1 of 4 (520 views)
Opposite of Chop? Can't Post

Hi all,

I need to remove the FIRST character of a variable.

Is there a function (such as chop) to do this?

Andrew


Recall
Novice

Dec 16, 2003, 10:28 AM

Post #2 of 4 (518 views)
Re: [andy7t] Opposite of Chop? [In reply to] Can't Post

The opposite of chop would be adding a character to the end of a string =)

Anyway, AFAIK there is no built in function but you can use a couple of other methods...

Code
$string =~ s/^.//;

or...

Code
substr($string, 0, 1) = '' if ($string and length($string));



(This post was edited by Recall on Dec 16, 2003, 10:29 AM)


andy7t
User

Dec 16, 2003, 10:32 AM

Post #3 of 4 (515 views)
Re: [Recall] Opposite of Chop? [In reply to] Can't Post

Thanks!

I'll know in the future.

I thought of something just after i posted:

$price= reverse $price;

chop $price;

$price=reverse $price;


uri
Thaumaturge

Dec 23, 2003, 10:31 PM

Post #4 of 4 (503 views)
Re: [Recall] Opposite of Chop? [In reply to] Can't Post


In Reply To
Anyway, AFAIK there is no built in function but you can use a couple of other methods...

Code
$string =~ s/^.//;

or...

Code
substr($string, 0, 1) = '' if ($string and length($string));



why do you do the tests for the second answer but not the first?

what happens in the first case if $string starts with "\n"? it needs the /s modifier for . to match \n

and in the second, what if $string is '0'?
that first test needs to be defined($string).

also, 4 arg substr is faster than lvalue substr.

uri

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives