Sponsored Content
Full Discussion: Accessing files with perl
Top Forums Shell Programming and Scripting Accessing files with perl Post 302199916 by chriss_58 on Wednesday 28th of May 2008 06:06:26 AM
Old 05-28-2008
Accessing files with perl

Hello i am new to Perl and i have a question.

I am trying to read a file that has the following format:

14/4/2008 8:42:03 πμ|10800|306973223399|4917622951117|1||1259|1|126|492|433||19774859454$
14/4/2008 9:13:08 πμ|10800|306973223399|306970097423|1||1264|1|126|492|878||19774859762$
14/4/2008 9:15:38 πμ|10800|306973223399|E-MAIL|1||1270|1|126|492|903||19774859792$
14/4/2008 9:05:50 πμ|10800|306973223399|306973223323|1|34||0|133|2530|816|4139063897|19775160876$
14/4/2008 8:15:57 πμ|10800|306973223399|306974439999|1|0||1|3|500|878|019D096290|19775241815$
$


I read the first line and i add the line to an array using the following code;
Code:
sub parse_csv {
    my $text = shift;
    my @new  = ();
    push( @new, $+ ) while $text =~ m{
       "([^\"\\]*(?:\\.[^\"\\]*)*)",?
           |  ([^|]+),?
           | ,
       }gx;
    push( @new, undef ) if substr( $text, -1, 1 ) eq ',';
    return @new;


The problem is that when in the file (for example line 2) two "||" exists the null value is not added to the array. So in the array less fields exist. How can i modify the code above in order for the null values to be addede in the array as well.

Thank you very much fo your help!

Last edited by Yogesh Sawant; 05-28-2008 at 09:09 AM.. Reason: added code tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Accessing Files on another drive

Hey..alright heres the deal I'm going to do a triple boot if you would Win98SE, Win2K, and Redhat Linux 7.1 now I have two HDs each with 30 gigs i've allowed one HD to the OS's with 10 gigs each...the third I intend to be one for windows to pull things thats compliant with both 98 and 2k and store... (2 Replies)
Discussion started by: PravusMentis
2 Replies

2. Shell Programming and Scripting

accessing variables declared in another perl script

Hi all, I have a perl script which declares two variables and calls another perl script which accesses those variables. But I am unable to access the variables in the called script. My script is as follows: my $ENV{a}="20"; system("perl called.pl"); and my called.pl contains: print... (3 Replies)
Discussion started by: gurukottur
3 Replies

3. Shell Programming and Scripting

accessing a function in ksh from perl

is it possible? Because I know we could use open(A, `abc.ksh`); to access a ksh, but is it possible to access just one (or more) function from the ksh script? (2 Replies)
Discussion started by: ahtat99
2 Replies

4. Shell Programming and Scripting

[Perl] Accessing array elements within a sed command in Perl script

I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows: $count = 0; while ( $count < $#test ) { `sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`; `cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies

5. Shell Programming and Scripting

Accessing VSS through Perl

Hi All, can you please let me know how to copy entire files in a directory of VSS to a local folder. i am using PERL to access the VSS. Thanks in Advance regards, aditya Mahi (1 Reply)
Discussion started by: adityamahi
1 Replies

6. Web Development

Accessing a Perl CGI script, security issue

Hi Everybody, I was wondering if it was possible for someone to gain access to my Perl CGI scripts before they are interpreted by Perl (mod_perl on apache2) i.e. getting a hold of my raw scripts and not the html output? Let's say I use the DBI module where I have the hostname, user and... (2 Replies)
Discussion started by: z1dane
2 Replies

7. Shell Programming and Scripting

Accessing Multiple files using for loop

Hi All, I have some files in my directory, and i want to pull all data using for loop....I am using following code but getting error..! for file in {file1, file2, file3, ..... filen} do L="$(tail -1 $file)";NUM=${L%%|*};DAT=${L##*|} echo $NUM>>filedata.txt done Error: tail:... (3 Replies)
Discussion started by: fidelis
3 Replies

8. Shell Programming and Scripting

PERL on windows accessing variables from a config file

Folks, I'm a perl moron, so please speak very slowly. : ) I'm modifying a build script that starts up an apache server. Now there is a .config file that hardcodes an old webserver path like this c:\oldWebserver. Now I don't want that hardcoded value, rather wish to use an... (3 Replies)
Discussion started by: MarkoRocko
3 Replies

9. Shell Programming and Scripting

Perl: accessing reference to variable inside hash.

Below is hash which contains reference to variables: my %mandatoryFields = ( 1 => \$msgtype, 2 => \$switchtype, 3 => \$card_nbr, 4 => \$natv_tran_type_code, 5 => \$amt_1 ); This... (0 Replies)
Discussion started by: som.nitk
0 Replies

10. Shell Programming and Scripting

Accessing files in batch

hai, I have a list of files having extension .sy in a folder. I want to find such files and print the first two columns of the files to new extension .tmp (1 Reply)
Discussion started by: sreejithalokkan
1 Replies
XPath::NodeSet(3)					User Contributed Perl Documentation					 XPath::NodeSet(3)

NAME
XML::XPath::NodeSet - a list of XML document nodes DESCRIPTION
An XML::XPath::NodeSet object contains an ordered list of nodes. The nodes each take the same format as described in XML::XPath::XMLParser. SYNOPSIS
my $results = $xp->find('//someelement'); if (!$results->isa('XML::XPath::NodeSet')) { print "Found $results "; exit; } foreach my $context ($results->get_nodelist) { my $newresults = $xp->find('./other/element', $context); ... } API
new() You will almost never have to create a new NodeSet object, as it is all done for you by XPath. get_nodelist() Returns a list of nodes. See XML::XPath::XMLParser for the format of the nodes. string_value() Returns the string-value of the first node in the list. See the XPath specification for what "string-value" means. to_literal() Returns the concatenation of all the string-values of all the nodes in the list. get_node($pos) Returns the node at $pos. The node position in XPath is based at 1, not 0. size() Returns the number of nodes in the NodeSet. pop() Equivalent to perl's pop function. push(@nodes) Equivalent to perl's push function. append($nodeset) Given a nodeset, appends the list of nodes in $nodeset to the end of the current list. shift() Equivalent to perl's shift function. unshift(@nodes) Equivalent to perl's unshift function. prepend($nodeset) Given a nodeset, prepends the list of nodes in $nodeset to the front of the current list. perl v5.16.2 2002-09-02 XPath::NodeSet(3)
All times are GMT -4. The time now is 06:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy