Write a Perl script which displays the NUMBER of lines in a text tile, then appends “My script is complete” to the file. This will require meto open the file twice, once to read everything in and once to append. Append is >> onemoretime.txt. Read is > onemoretime.txt. The Britney Spears lyrics is in OneMoretime.txt that needs to be read and appended.
Onemoretime.txt contents
Oh baby, baby
How was I supposed to know
That somethin’ wasn’t right?
Oh baby, baby
I shouldn’t have let you go
And now you’re outta sight
My loneliness is killin’ me
I must confess I still believe
When I’m not with you I lose my mind
Give me a sign, hit me baby one more time
On Thu, 16 Aug 2012 20:36:02 +0000, renegadeviking wrote:
> How would type up such a Perl Script?
I’ll have to admit that this sounds an awful lot like a homework
assignment. As such, it wouldn’t be prudent to just give you the answer,
but perhaps you’re working through an issue with a script you’ve started
on?
On Thu, 16 Aug 2012 22:16:02 +0000, renegadeviking wrote:
> I need this to work, thanks. If I am working on openSUSE at work, is it
> homework. Is it my username?
What’s not working with it?
No, it’s not your username, it’s just the nature of what the script is
doing. It reads like a homework question - and we do get our share of
students coming into the programming group looking for “help” in the form
of “I can’t figure out this assignment and want someone to do it for
me” (though it’s never explicitly stated that way).
So we tend to be careful about providing direct answers to questions that
appear to be school assignments.
We also ask that you stick to one thread per topic. I responded to your
other one before seeing this one, but they appear to be the same
homework question.
Another reason this is a homework question: Nobody would write a Perl
script to do what ‘grep’ can do in one line unless it was as a tiny
practice assignment.
Good luck.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
On 08/17/2012 01:47 AM, ab wrote:
> Nobody would write a Perl
> script to do what ‘grep’ can do in one line unless it was as a tiny
> practice assignment.
Am 17.08.2012 01:47, schrieb ab:
> Another reason this is a homework question: Nobody would write a Perl
> script to do what ‘grep’ can do in one line unless it was as a tiny
> practice assignment.
I disagree, you would do that and not rarely but often (cannot speak
about Perl, but that’s programming language agnostic) if the same
program needs to run on different platforms or if it is part of a larger
program and a call to an external tool is in general a problem
(security, no defined API to interface with …).
Sorry, could not resist.
On the other hand this problem is so funny, it can only be a homework or
textbook problem.
–
PC: oS 12.2 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.8.4 | GeForce GT 420
ThinkPad E320: oS 12.1 x86_64 | i3@2.30GHz | 8GB | KDE 4.8.5 | HD 3000
eCAFE 800: oS 12.1 i586 | AMD Geode LX 800@500MHz | 512MB | KDE 3.5.10
Martin Helm wrote:
> In fact Perl has a grep command.
True, but I sometimes still call system grep from within my perl
programs. It all depends on what you’re searching for and how big the
file(s) you’re searching are.
The reason for 'grep and not ‘wc’ is because you need lines that are not
blank. wc will return them all, and grep -cv '^\s*$' will return just
the number you’re after instead.
Good luck.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
Am 17.08.2012 17:33, schrieb ab:
> The reason for 'grep and not ‘wc’ is because you need lines that are not
> blank.
Now I seem to be blind, where do you see that requirement?
–
PC: oS 12.2 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.8.4 | GeForce GT 420
ThinkPad E320: oS 12.1 x86_64 | i3@2.30GHz | 8GB | KDE 4.8.5 | HD 3000
eCAFE 800: oS 12.1 i586 | AMD Geode LX 800@500MHz | 512MB | KDE 3.5.10
First I do not agree. Lay-out is part of the lyrics IMHO. Bit I admit that I can be wrong. After all this is not a forums about singsongs.
It is a computer technical forum and the OP specified his requirements clearly in computer technical terms as
[QUOTEwhich displays the NUMBER of lines in a text tile][/QUOTE]
I like to point to the word “file” that has a well know meaning in a forum like this.