[32014] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3278 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 7 14:09:30 2011

Date: Mon, 7 Feb 2011 11:09:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 7 Feb 2011     Volume: 11 Number: 3278

Today's topics:
        Comparison of 2 files and generating the output based o <pradeep.bg@gmail.com>
    Re: Comparison of 2 files and generating the output bas <cartercc@gmail.com>
    Re: Fully functional email client <paul@pstech-inc.com>
    Re: Fully functional email client <hjp-usenet2@hjp.at>
        How find all overlapping pattern? <pengyu.ut@gmail.com>
    Re: How find all overlapping pattern? <jl_post@hotmail.com>
    Re: How find all overlapping pattern? <cartercc@gmail.com>
    Re: Sys::Syslog question <dave@invalid.invalid>
    Re: upload module to CPAN (http client) <hjp-usenet2@hjp.at>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 6 Feb 2011 23:27:07 -0800 (PST)
From: Deepu <pradeep.bg@gmail.com>
Subject: Comparison of 2 files and generating the output based on comparison
Message-Id: <1fb7abf8-0131-4f85-adfa-b8364c3e8127@q2g2000pre.googlegroups.com>

Hi All,

I need some help for a scenario explained below.

File A has content as below:

-from logic.blocka.reg*  -to logic.blockb.temp_reg*
-from logic.blockb.reg*  -to logic.blockc.*reg*
-from logic.blockc.*reg* -to logic.blockb.reg*

File B has content as below:

tb/device/logic/blocka/reg_0/Q
tb/device/logic/blocka/reg_1/Q
tb/device/logic/blocka/reg_2/Q
tb/device/logic/blocka/reg_3/Q
tb/device/logic/blockb/reg_0/Q
tb/device/logic/blockb/reg_1/Q
tb/device/logic/blockc/ff_reg_0/Q
tb/device/logic/blockc/ff_reg_1/Q

tb/device/logic/blockb/temp_reg_0/D
tb/device/logic/blockb/temp_reg_1/D
tb/device/logic/blockb/temp_reg_2/D
tb/device/logic/blockb/temp_reg_3/D
tb/device/logic/blockc/ff1_reg_0/D
tb/device/logic/blockc/ff1_reg_1/D
tb/device/logic/blockb/reg_0/D
tb/device/logic/blockb/reg_1/D


Now i need to look into File A and for 1st line for example

"-from logic.blocka.reg*  -to logic.blockb.temp_reg*"

Look into File B for the path name after 'from' and 'to' and then
prepare an output as below:


always @ (tb.device.logic.blocka.reg_0.Q)
  begin
    @ (tb.device.logic.blockb.temp_reg_0.D);
  end

always @ (tb.device.logic.blocka.reg_1.Q)
  begin
    @ (tb.device.logic.blockb.temp_reg_0.D);
  end

always @ (tb.device.logic.blocka.reg_2.Q)
  begin
    @ (tb.device.logic.blockb.temp_reg_0.D);
  end

always @ (tb.device.logic.blocka.reg_3.Q)
  begin
    @ (tb.device.logic.blockb.temp_reg_0.D);
  end


Thanks for your time..


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

Date: Mon, 7 Feb 2011 07:09:11 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Comparison of 2 files and generating the output based on comparison
Message-Id: <172a6aa3-4e6b-475b-9d5f-b214145c0b02@o18g2000prh.googlegroups.com>

On Feb 7, 2:27=A0am, Deepu <pradeep...@gmail.com> wrote:
> I need some help for a scenario explained below.

This is a typical data munging task. Pseudo code for your script is as
follows, at least as a first step:

open file A
for each line in file A
 - split the line
 - stuff the values into a suitable data structure (perhaps %A)
close file A

open file B
for each line in file B
 - split the line
 - stuff the values into a suitable data structure (perhaps %B)
close file B

iterate through %A
 - if there is a match with an element of %B, print

From the appearance of your data, you could probably throw away the
first three directories, tb, device, and logic. It strikes me that (as
a first try) you might want to replace the delimiter in each line to a
common delimiter, perhaps a colon, save the whole thing as a string,
and then use a regular expression to match against the string.

From there, you can optimize, perhaps by just saving the values in the
first file as an array of strings, and directly match the values in
the second file without using a second data structure. This depends on
the nature of your data, and if your data is sorted in some kind of
way, the task become much easier.

Your question isn't a Perl question as such, but more of a general
question applicable to whatever language you would want to use,
although Perl can certainly handle this task with ease and speed.

CC.


>
> File A has content as below:
>
> -from logic.blocka.reg* =A0-to logic.blockb.temp_reg*
> -from logic.blockb.reg* =A0-to logic.blockc.*reg*
> -from logic.blockc.*reg* -to logic.blockb.reg*
>
> File B has content as below:
>
> tb/device/logic/blocka/reg_0/Q
> tb/device/logic/blocka/reg_1/Q
> tb/device/logic/blocka/reg_2/Q
> tb/device/logic/blocka/reg_3/Q
> tb/device/logic/blockb/reg_0/Q
> tb/device/logic/blockb/reg_1/Q
> tb/device/logic/blockc/ff_reg_0/Q
> tb/device/logic/blockc/ff_reg_1/Q
>
> tb/device/logic/blockb/temp_reg_0/D
> tb/device/logic/blockb/temp_reg_1/D
> tb/device/logic/blockb/temp_reg_2/D
> tb/device/logic/blockb/temp_reg_3/D
> tb/device/logic/blockc/ff1_reg_0/D
> tb/device/logic/blockc/ff1_reg_1/D
> tb/device/logic/blockb/reg_0/D
> tb/device/logic/blockb/reg_1/D
>
> Now i need to look into File A and for 1st line for example
>
> "-from logic.blocka.reg* =A0-to logic.blockb.temp_reg*"
>
> Look into File B for the path name after 'from' and 'to' and then
> prepare an output as below:
>
> always @ (tb.device.logic.blocka.reg_0.Q)
> =A0 begin
> =A0 =A0 @ (tb.device.logic.blockb.temp_reg_0.D);
> =A0 end
>
> always @ (tb.device.logic.blocka.reg_1.Q)
> =A0 begin
> =A0 =A0 @ (tb.device.logic.blockb.temp_reg_0.D);
> =A0 end
>
> always @ (tb.device.logic.blocka.reg_2.Q)
> =A0 begin
> =A0 =A0 @ (tb.device.logic.blockb.temp_reg_0.D);
> =A0 end
>
> always @ (tb.device.logic.blocka.reg_3.Q)
> =A0 begin
> =A0 =A0 @ (tb.device.logic.blockb.temp_reg_0.D);
> =A0 end
>
> Thanks for your time..



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

Date: Sun, 6 Feb 2011 03:52:38 -0500
From: "P E Schoen" <paul@pstech-inc.com>
Subject: Re: Fully functional email client
Message-Id: <xjt3p.68760$be.42904@newsfe05.iad>

"iaoua iaoua"  wrote in message=20
news:65407d4c-52b2-489e-aedd-6679a0bd817c@glegroupsg2000goo.googlegroups.=
com...

> Newbie alert. I'm new to this newsgroup so please
> be nice to me. I'm not completely new to Perl but not
> exactly a Guru and not exactly much more than a
> complete novice so please bear with me.

> Basically, I need a command line version of Thunderbird
> but that already extracts the new line of text as input to
> my agent. Surely, there must be something like that out
> there already done in Perl. Can anyone point me to
> anything? Or is it noses to the grindstone time?

I'm not sure I understand what you need, but I have recently developed =
some=20
simple Perl and PHP scripts that take user input, add it to a database, =
and=20
then put together HTML that is echoed to the user. It also generates=20
formatted HTML files for use by another HTML page, and it emails the=20
submitted content to me along with information about the user. It is=20
password protected and designed to thwart DoS attacks by incorporating a =

file lock and delay which will bounce repeated accesses. And it also =
uses an=20
HTML purifier to clean up any possibly malicious HTML submitted by the =
user.

So, if you could use a website that allows user input, rather than =
having=20
users send emails, the rest of the project should be just a matter of=20
providing the feedback to the user until the desired resource is =
determined,=20
and then the user could click the URL that is recommended to see if it =
what=20
was needed.

I've become more comfortable with PHP than Perl, but I'm a novice at =
both.=20
However, I've been able to do what I needed to do, and now I'm just =
cleaning=20
it up and adding features.

I am not really familiar with Thunderbird, but there are simple mailer=20
functions in Perl and PHP that are easy to implement. And I'm not really =

sure if email is even needed for your application. You just need a =
website=20
with hooks to your main application. For any client-side email, the user =

would use his own default sendmail application (as with an href=20
"sendto:emailaddy"), and your server-side script can use the mail =
programs=20
supplied by the host. There may be other considerations depending on =
where=20
your application resides and what form of I/O it requires.

Paul=20



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

Date: Sun, 6 Feb 2011 17:49:03 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Fully functional email client
Message-Id: <slrniktk7v.g4v.hjp-usenet2@hrunkner.hjp.at>

[Please format your postings to reasonable line length (about 70
characters/line). News clients do not generally wrap long lines and long
lines are hard to read. I have reformatted your posting.]


On 2011-02-06 02:23, iaoua iaoua <iaoua.iaoua@gmail.com> wrote:
> Anyway, apart from machine tranlation research in my spare time I have
> developed a conversational agent that dialogues with users to find out
> what they are really looking for (gone are the days of simple keyword
> search). I have a growing base of experimental users for my alpha
> release who currently need to come into my office to use the system as
> it is not web borne. The system can take some time to answer questions
> because of the comlexity of the task (the system is still learning).
> It asks the user questions to figure out what they want and then sends
> them off to the right website or business that has the products,
> services, information or free downloads that they require
>
> e.g.
>
> Hi, how can I help you?
> Where can I download music?
> Erm, lots of different places what were you looking for exactly?
> A song by U2?
> Which song exactly?
> ...
>
> This goes on until the system has completely matched the user's
> requirements. It can take some time for the inference engine to figure
> out a satisfying answer and if the answer turns out not to be
> satisfying then the system has to go into dialogue to make new
> suggestions and learn from user feedback. As the system is slow at
> decision making my growing user base has asked if they can play with
> the system by email instead of having to sit in my office and wait for
> a long time for the system to generate responses.

In general I agree with Paul: Email seems to be an awkward choice for
what seems to be a dialog consisting of one-line messages. However, if
the response times are very long (several minutes or more) the
asynchronous nature of email is an advantage. As an alternative you
might consider an instant messaging system like XMPP (also known as
Jabber).

Perl has a number of modules for accessing mail at various places (local
folders, POP, IMAP, ...), parsing it, and sending it by various means
(local sendmail process, SMTP/Submission, ...). Look on
<http://search.cpan.org/>.

What works for you depends very much on your system (Windows, Linux,
MacOS?), how you access and send mail (can you receive and send mail
locally or do you need IMAP/POP/SMTP?), your users (can you teach them
to send only plain text or do they use HTML mails? How about quoting?)



> So what I basically need is a solution I can drop my conversational
> agent into. Some kind of fully functional email client that already
> absracts away the details of receiving and sending messages.
> Generating message ids for threading. Extracting the new text which is
> the response to the last email etc.

I'm not aware of an out of the box solution for this. Most of it can be
cobbled together from existing modules with a few lines of code. The
hardest part is probably "extracting the new text which is the response
to the last email" since users are notoriously bad at following
conventions in email.

I think I would use XMPP instead of mail for this. The Net::XMPP module
seems to rather easy to use (although so far I have only used it to send
messages, not to receive them) and IM fits the dialog structure better.

	hp


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

Date: Mon, 7 Feb 2011 07:31:39 -0800 (PST)
From: Peng Yu <pengyu.ut@gmail.com>
Subject: How find all overlapping pattern?
Message-Id: <d98b8090-533d-442b-b310-5a67b149acb6@k22g2000yqh.googlegroups.com>

$string="abcabcabc";
@findall = $string =~ /abcabc/g;
print scalar(@findall), "\n";

The above commands will print 1 rather than 2. Because there are two
overlapping 'abcabc', I'd like to get 2. I'm wondering what is the
correct way to find all overlapping regexes. (Note that I gave
'abcabc' as an example, but it could be any complex regex) Thanks!


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

Date: Mon, 7 Feb 2011 08:02:22 -0800 (PST)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: How find all overlapping pattern?
Message-Id: <745fcc04-44c7-40ed-9977-4c9924c433bb@k15g2000prk.googlegroups.com>

On Feb 7, 8:31=A0am, Peng Yu <pengyu...@gmail.com> wrote:
> $string=3D"abcabcabc";
> @findall =3D $string =3D~ /abcabc/g;
> print scalar(@findall), "\n";
>
> The above commands will print 1 rather than 2. Because there are two
> overlapping 'abcabc', I'd like to get 2. I'm wondering what is the
> correct way to find all overlapping regexes. (Note that I gave
> 'abcabc' as an example, but it could be any complex regex) Thanks!


Dear Peng Yu,

   Here's one way to do it:

      while ($string =3D~ m/(abcabc)/g)
      {
         push @findall, $1;
         pos($string) =3D $-[0] + 1;
      }

If you prefer to implement it in one line of code, you can do this:

      push(@findall, $1) and pos($string) =3D $-[0] + 1
         while $string =3D~ m/(abcabc)/g;

   Here's the explanation of what is happening:  Normally, m//g and
s///g both make additional matches AFTER (or right at) the end of the
previous match, meaning that you can't directly use them to find
overlapping patterns.  However, inside a while($string =3D~ m//g) loop
you can manipulate the pos($string) variable to force m//g to begin
looking wherever you want -- or in your case, one character after the
start of the last match.  (You have to start one (or more) characters
after, because if you started at (or before) the start of the last
match the loop would be infinite.)

   As for the $-[0] variable, that's the first element of the @-
array, which you can look up with "perldoc -v @-".  $-[0] is basically
the start of the last successful match, so ($-[0] + 1) would be the
earliest where you would want to continue your search for overlapping
patterns.

   I hope this helps, Peng Yu.

   Cheers,

   -- Jean-Luc


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

Date: Mon, 7 Feb 2011 08:46:53 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: How find all overlapping pattern?
Message-Id: <a3b58d13-ba86-41c3-8370-100ce37eb416@i39g2000prd.googlegroups.com>

On Feb 7, 10:31=A0am, Peng Yu <pengyu...@gmail.com> wrote:
> $string=3D"abcabcabc";
> @findall =3D $string =3D~ /abcabc/g;
> print scalar(@findall), "\n";
>
> The above commands will print 1 rather than 2. Because there are two
> overlapping 'abcabc', I'd like to get 2. I'm wondering what is the
> correct way to find all overlapping regexes. (Note that I gave
> 'abcabc' as an example, but it could be any complex regex) Thanks!

You don't have to use a regular expression in a case like this. You
can use index($string, $substring, $position) in a loop, ending the
loop which $position is less than zero. This is how you might do it in
a language like C.

Sometimes, the simpler way is better.

CC.


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

Date: Sun, 6 Feb 2011 11:34:09 +0000 (UTC)
From: "Dave Saville" <dave@invalid.invalid>
Subject: Re: Sys::Syslog question
Message-Id: <fV45K0OBJxbE-pn2-KgdtT9iRUmc1@localhost>

On Sat, 5 Feb 2011 10:42:31 UTC, Eric Pozharski 
<whynot@pozharski.name> wrote:

> with <fV45K0OBJxbE-pn2-djbSFegGnbeu@localhost> Dave Saville wrote:
> > On Fri, 4 Feb 2011 12:36:06 UTC, Martijn Lievaart <m@rtij.nl.invlalid>
> > wrote:
> >
> >> On Fri, 04 Feb 2011 11:50:46 +0000, Dave Saville wrote:
> *SKIP*
> >> > The question is, which is best practice?
> >> > 
> >> > 1) Inside the read pipe loop - openlog, write, close log for every
> >> > line.
> >> > 2) Openlog outside the pipe read loop and write each line as it
> >> > comes?  ie keep the file open.
> >> 
> >> What's wrong with option 2?
> >> 
> >
> > Well I am not sure if keeping an open connection to the syslogd daemon
> > for days on end is a good idea :-)
> 
> Sysloging over network is of UDP kind, thus no-connection.  OTOH, if
> there's any connection with /dev/log I can't say without investigation
> (and, honestly, I'm not interested).  And please note,  fork(2) is
> costly.  open(2) isn't.  You can safely (if you wish) open-write-close.
> With amounts of bytes you're going to syslog you'll see no problems.
> 

Thanks - going for option 2 and see if I get any problems.
-- 
Regards
Dave Saville


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

Date: Sun, 6 Feb 2011 14:20:29 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: upload module to CPAN (http client)
Message-Id: <slrnikt80t.g4v.hjp-usenet2@hrunkner.hjp.at>

On 2011-02-05 22:48, Dr.Ruud <rvtol+usenet@xs4all.nl> wrote:
> On 2011-02-05 17:09, brian d foy wrote:
>> In article
>> <5964fa37-8869-43cd-a69e-37d1506d3e19@r19g2000prm.googlegroups.com>,
>> Loofort<loofort@gmail.com>  wrote:
>
>>> I think to prefix packages with "CTX" - meaning "context" since http
>>> (and specially ftp) works in context - pass the cookies, understand
>>> relative links, keep alive connections etc.
>>
>> PAUSE has some naming advice. There's not much context for CTX, so you
>> might choose another top-level namespace :)
>>
>> https://pause.perl.org/pause/query?ACTION=pause_namingmodules
>
> "pause.perl.org uses an invalid security certificate."


It's signed by CAcert. Your browser probably doesn't have the root
certificate for that CA installed. You can get it from
http://www.cacert.org/index.php?id=3. (or
https://www.cacert.org/index.php?id=3 but there your browser will
complain about an invalid certificate, too).

	hp


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 3278
***************************************


home help back first fref pref prev next nref lref last post