Computing.Net > Forums > Programming > Regarding perl reg exp

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Regarding perl reg exp

Reply to Message Icon

Name: raviepic3
Date: October 27, 2008 at 02:19:01 Pacific
OS: XP
CPU/Ram: 512
Product: p4
Comment:

#!\C:\Perl\bin
use strict;
use warnings;
my $cont;
open my $file,"Contacts.CSV" or die;
open my $write,">>sample.csv" or die;
while(<$file>)
{

$cont=$_;
$cont=~s#.{50}# #;
print $write $cont;
}

here wat the problem is sample.csv getting created but the regular expression not working...plz help


i wanted to extract first 50 chars from a line

programming newbie :)



Sponsored Link
Ads by Google

Response Number 1
Name: FishMonger
Date: October 27, 2008 at 05:17:07 Pacific
Reply:

A regex can be used to extract a substing, but in this case it would be much more efficient to use the substr function since that is what it was designed for.

$cont = substr($cont, 0, 50);


0

Response Number 2
Name: raviepic3
Date: October 27, 2008 at 10:26:35 Pacific
Reply:

hey problem solved...thank you neways for dedicating ur time on this :)

programming newbie :)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Regarding perl reg exp

Perl reg exp www.computing.net/answers/programming/perl-reg-exp/17672.html

about regular expression www.computing.net/answers/programming/about-regular-expression/5968.html

How to write html code in perl? www.computing.net/answers/programming/how-to-write-html-code-in-perl/12668.html