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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Storing a variable amount of text?


New User

Dec 9, 2011, 8:25 AM

Post #1 of 2 (541 views)
Storing a variable amount of text? Can't Post

Hello all,

I'm trying to store some text into a variable...
The text is in between double quotes but the length is variable. Also I need to ignore a line if it contains a certain value in those double quotes, such as "CODE". The remaining line's text needs to be stored in a different variable.

so here would be the example file:
"abc","other fields"
"abcdef","other fields"
"abcdefghij","other fields"

Previously the fields were fixed 16 characters so I did this:
my $1stfield = substr($line,0,16);
my $remaining = substr($line,16);

Could someone please help me solve this? Many thanks for your time.


Dec 9, 2011, 12:32 PM

Post #2 of 2 (507 views)
Re: [ofmike] Storing a variable amount of text? [In reply to] Can't Post

use strict; 
use warnings;
while (<DATA>) {
next if /^"CODE"/;
(my $firstfield, my $remaining) = /^"([^"]*)"(.*)$/;
print $firstfield, "<-->", $remaining, "\n";
"abc","other fields"
"abcdef","other fields"
"abcdefghij","other fields"

Good Luck,


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

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