develooper Front page | perl.beginners | Postings from August 2009

Re: Attentipn Please!! Need A Perl script to read the UIDs from two text files having the details in the format as given in the file(lLDIF format)

Thread Previous | Thread Next
From:
Ian
Date:
August 17, 2009 10:28
Subject:
Re: Attentipn Please!! Need A Perl script to read the UIDs from two text files having the details in the format as given in the file(lLDIF format)
Message ID:
6845b8890908171028r5d55f2aehb255d11dc6082111@mail.gmail.com
This is how I would do it.

To every one else, please feel free to critique my perl programming skills.
I'm a Mainframe Assembler programmer and still learning perl. Any critique
will just help to improve my skills.

use strict;
> use Data::Dumper;
> my $inpf = 'student.txt';
> open (DATA, $inpf) or die "Can't open file $inpf!\n";
>
> # read file
> my (%idhash);
> my $line;
> while ($line = <DATA>) {
>         chomp($line);
>
>     if ($line =~ /^dn:\s+uid=(s\d{2}-\d{1}-\d{1}-\d{1,3})/) {
>             my $id = $1;
>             my $recd = 1;
>         while ($recd == 1) {
>             if ($line =~ /^uidNumber:\s+(\d{4,})/ ){
>                 my $uid = $1;
>                 $idhash{$id} = $1;
>                 $recd = 0;
>                 }
>             else {
>                 $line = <DATA>;
>                 chomp($line);
>
>                 }
>         }
>     }
>
> }
> print Dumper(%idhash), "\n";
>
> while ( (my $snum, my $sid) = each(%idhash) ) {
>     print "Student = $snum\tuidNumber = $sid\n";
>     }
>
> END;
>


Thanks
Ian


On Mon, Aug 17, 2009 at 10:11 AM, Jyotishmaan Ray <jyotishmaan@yahoo.com>wrote:

> Dear All,
>
> I have to read the uid from this file for each student entry, which is
> itself a LDIF file, and extract it in another file, in a serial order.
>
>
> Can you provide me the simplest way to do it.
>
>
>
> Thanks,
> Jyotishmaan Ray
> Moderator Of Spirituality-Paradise Group
> http://yahoogroups.com/group/Spirituality-Paradise
>
> Are You Spiritually Aware  !!! Are You Enjoying Yourself  !!!  See What All
> You Had Been Missing !!!!
> Please Join Immediately By Sending A Blank Mail @
> Spirituality-Paradise-subscribe@yahoogroups.com
>
>
>
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>


-- 
Ian
http://www.cicsworld.com

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About