Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

file pointer question

by kprasanna_79 (Hermit)
on Sep 18, 2006 at 21:59 UTC ( [id://573614]=perlquestion: print w/replies, xml ) Need Help??

kprasanna_79 has asked for the wisdom of the Perl Monks concerning the following question:

Revered Monks,

I have a file in which i have data scrambled here and there with in few lines. see the below sample

the file wil be like this.. head 1.3; branch ; access ; symbols ; locks ; strict; comment @@; format binary; 1.3 date 2006.04.04.13.57.13; author d; state Exp; branches ; next 1.2; 1.2 date 2006.04.04.08.55.21; author d; state Exp; branches ; next 1.1; 1.1 date 2006.03.27.15.45.18; author d; state Exp; branches ; next ; ext

i need to collect the last version number, date and the latest version date and number. So i some how managed to put this info in a new file and to proceed further i need to know is there any filepointer function which can traverse to the line number specified or file open options which read from the last line of the file.

Any ideas or suggestions is appreciated

-Prasanna.K

Replies are listed 'Best First'.
Re: file pointer question
by ikegami (Patriarch) on Sep 18, 2006 at 22:36 UTC
    local $/ = ""; # Paragraph mode. my $newest_ver; my $newest_date; my $oldest_ver; my $oldest_date; while (<DATA>) { next unless /^(\d\S*)/; my $ver = $1; next unless /^date ([^\s;]+)/m; my $date = $1; if (not defined $oldest_ver) { $newest_ver = $oldest_ver = $ver; $newest_date = $oldest_date = $date; next; } if ($date lt $oldest_date) { $oldest_ver = $ver; $oldest_date = $date; } else { $newest_ver = $ver; $newest_date = $date; } } if (defined $oldest_date) { print("oldest: $oldest_ver on $oldest_date\n"); print("newest: $newest_ver on $newest_date\n"); } else { print("No data found\n"); }

    Give the lack of information, I made some assumptions.

    • I assumed blank lines seperate the records.
    • I assumed the version appears on the first line of a record.
    • I assumed the version appears at the start of a line.
    • I assumed "date" appears at the start of a line.
    • I assumed the dates will be in a string sortable format.

    Notes:

    • I didn't assume the records are in order.
    • The "head" and "next" fields are not used.
    • Unrecognized data is ignored.
Re: file pointer question
by Tanktalus (Canon) on Sep 18, 2006 at 22:04 UTC

    You may be looking for seek and tell or even File::ReadBackwards - but given the actual contents here, you may be better off looking at the Cvs modules.

    That said, it's not entirely clear to me what your definition of "last" is - are you looking for 1.1 or 1.3 in your example? 1.1 is the last one in the file, but 1.3 is the last (latest) one put into the file.

      I am looking for the latest version date(1.3) and first version date(1.1).

Re: file pointer question
by Anonymous Monk on Sep 19, 2006 at 12:38 UTC
    Why don't you use Rcs::Parser module? (or even Rcs one!)
    use Rcs::Parser; use strict; my $rcs=new Rcs::Parser; $rcs->load("filename,v"); print "Last: ".$rcs->version() ." ".$rcs->date()."\n"; print "First: 1.1 ".$rcs->date("1.1") ."\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://573614]
Approved by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-24 02:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found