AWK embeded PERL

Hello Guys,

I am refering to this great forum once again for help.
After various attempts at this, I am still failing to obtain the desire effect.

I have to write a perl script which:
1- reads two values from the user (e.g name & passwd)
2- check each value against a file containing the authentic values
3- redirect the user according to his credentials, e.g
if this user is correctly identified (and granted he/she matches
another criteria), he is then directed to a page that only his
criteria allows him/her.
else (ie credentials incorrect)
user is directed to some error page.

-----------------------------------------------------------------------------

So far I was able to:
open a file in perl
read the content of the file
read the two values ok

however, I don't know how to "awk" each field of the credential file so that I can put each entry inside a separate perl variable, and then check them against the user's ones.

the awk command I am trying to emulate is:
awk -F: '{print $x}' myfile

then I wish to send the content of $x into a perl variable :frowning:

N.B I realise that this forum is not meant to write me an entire program, and indeed I do not want that, since I actually want to learn how to do this. However I do welcome any help in this direction.

Thanks in advance

Da Bionic one !

Are you trying to pull the content from myfile such as:

awk -F: '{print $1}' myfile

Are you looking output $1 into another file and then use that file as the input of your Perl script? If so, I think that you should be able to:
awk -F: '{print $1}' myfile >> $INPUT

Right? I am still rusty so I am asking as well. Sorry if I am not much help.

Hello Mirv, (and Hello Everyone)

Thanks for your fast response.
I am actually trying to read the content of myfile, somehow.
then from perl, extract fields from each record (file line).

so in normal unix script it looks like the awk script above, but I don't know if I can embed awk inside perl, and if so, how can I ?
otherwise, I am looking at using regular expressions, from perlre, and I found this:

if (/Time: (..) : (..) : (..)/) { # parse out values
$hours = $1;
$minutes = $2;
$seconds = $3;
}

Somehow, this retrieves each (colon separated) time field.
I would like to use something similar in order to retrive my fields.
e.g
myfile should look like this

login passwd credential
toto:totopass:totocred
mama:mamapass:mamacred
didi:didipass:didicred

Inside my perl script, I wish to:
1- open this file in READONLY
2- use some sort of look to scan through each record (file line)
3- retrieve each field, e.g $1 $2 $3
4- store each $x variable inside a perl variable (if the letter retrieving technique is not done in perl)

Many thanks for your efforts

Like I said I am rusty...especially with shell scripting...but that's why I am here! :smiley:

So is this going to be a patch process that you are going to be running and that's why you need this info? I'm just curious is all. Now there is another way to get those field you want without awk, it with the cut command. I believe it's cut -c but you can man cut to see all the switches. I am pretty sure that you can use awk inside of Perl. As far as implementing it, you would be better off asking one these gurus here. I think that you can use it just like in a KSH script but not sure. You could always create a test file and test it out, right? :wink: Now do you need to each field ($1, $2, and $3) to go into their own files respectively or would you only one file be enough for you to retreive your info?

Hello MIRV (and HELLO EVERYONE)

Thanks for your reply.
I believe that you meant a batch, as opposed to a patch process ?
Well, am hoping to use it to secure my website. I have written a html form which prompts the user for his credentials, and then I get the perl script to check the credentials, before redirecting the user to the appropriate page.

I am really not sure how to integrate normal shell commands into a perl script. Earlier I even tried the [echo] command, but it is simply ignored.

Sorry, guys, but this is quite a desperate situation, and I would appreciate some help in this matter. (or at least some pointer)

Many thanks again

sosthene

Yeah I meant batch..hehehe!! Sorry I cannot help man...Like I said before I am trying to get back into the swing of things, so if you find a good fix..please post it for us!

Thanks,
MIRV

Hey guys, just a quick question please:

how can I do this in perl ?

string:
"name : passwd"

retrieve "name" into variable $name
retrieve "passwd" into variable $passwd

This is in short what my problem is.

Many thanks

Da Bionic Fysh

the function you are looking for is split(). Read up on it in Learning Perl by Oreilly or any other Perl resource that you have. Or follow this link to perl.com http://www.perldoc.com/perl5.6/pod/func/split.html