Harjit Singh wrote:
The following code is what I used to check if item number could be
detected for the file I sent in the earlier email.

Did you send email to my [EMAIL PROTECTED] address? If the message in the user part of the address isn't sufficient, I can tell you that I never received your message. ;-)

The code seems to have failed and need a advise on it..

#!C:\perl\bin\perl5.6.1

Where is

    use strict;
    use warnings;

??

$file1 = ' C:\perl\bin\dummy.txt' ;
------------^
??
    my $file1 = 'C:\perl\bin\dummy.txt';

open (INFO, "< $file1 ") or die "Can't open $file: $1";
while (<INFO>)

I don't think it's a good approach to read the file line by line. I would slurp it into a scalar variable.

    $_ = do { local $/; <INFO> };

{
 if ($test = ~ "/2\.2\./d+\./d+\./d+"){

What on earth is that??

- When and how was $test populated?

- The =~ operator does not include any space.

- You haven't even learned the most basics about Perl regular
expressions, have you? Please start studying

    perldoc perlrequick

The file is of the following format:

---------------------------------------------------------------------------
2.2.4.3.4 XXXXXXX
 This is test of test
 for use by Sunny: 1
 as stated in 2.2.5.6.1
2.2.5.6.9 YYYYYYYYYY
Note 2: This function consolidates a number of former sections from 3.2.4.
 for use by Sunny: 2
 as discussed in 2.1.2.1
--------------------------------------------------------------------------

The file shows two items start with 2.2.* and additional detail
underneath it such as Sunny: 1 for 2.2.4.3.4 or Sunny: 2 for
2.2.5.6.9. I want to be able to break the file capturing its item
number along with number for Sunny: for each of the listed item
number.  The item number always starts in the beginning of line.

Assuming you have slurped the file into the $_ variable, you should be able to build a regex and do something like this:


    print "Segment: $1 - Sunny: $2\n" while /$re/g;

But first you must of course learn how to write a regex...  Besides
the suggested docs above, you may want to check out the qr// operator
in "perldoc perlop".

Good luck!

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to