Hello - I am new to Perl, and looking for some much needed direction.
I am trying to get a basic formula in place (within an existing IF
statement) that will serve to increase my price (i.e., "$new_price")
by the following formula:
=PRICE divided by 0.8 plus 15
In other words, if the Price is e
Rob,
> Your response dovetails nicely with my next question. The module I'm
> working in begins as follows:
>
> use warnings;
> use strict;
> use CGI qw/:standard center strong *big delete_all/;
Because the code you have included does not specifically say so I have to
guess that:
package NotShow
Jaws,
> DBD::mysql::st execute failed: Duplicate entry 'sample' for key 1 at
> ./addvpdnuser.pl line 17, <> line 1.
> DBD::mysql::st execute failed: Duplicate entry 'sample' for key 1 at
> ./addvpdnuser.pl line 17, <> line 1.
> [EMAIL PROTECTED] util]#
This is probably happening because the table
Jeff,
> Jenda,
>
> You CANNOT do what you are suggesting.
My guess is that at one time it was allowable. If someone knows what version
of Perl allowed loop control modifiers in do{ } blocks (or if they were
never allowed) I would like to know. I am using v5.8.0 and I was surprised
to try:
$ perl -
Yannick,
$ perl -e '
> %ch = (h1 => {}, h2 => {});
> for (keys %ch) {
> print"$_\n";
> }'
h1
h2
> Hi,
Hello,
> I'm just trying to make a structure with a hash containing some
> references to other (yet unused) hashes.
see above.
>
> So what I wrote this:
>
> $intHash1Ref = {};
> $intHash2Ref =
> Greetings!
Hello
>
> I'm trying to do some Perl for a non-profit organization. The computer
> administrator doesn't know very much about Perl or about the server.
> If I were to ask him what Perl modules were available, he'd probably
> just have to call somebody else and get back to me. Is the
Jim,
Some time ago a Computer Sci student was working on Linked Lists and
posted some code she needed help with.
> How would such a thing be done with Perl?
Preuse, run, modify and complete this code (it needs a way to remove a
center link, amoung other things.
I don't take credit for this code
ktb, Wiggins,
Another perspective:
text.txt contains:
return 'My Full Name with middle initial';
#!/usr/bin/perl -w
use strict;
my $name = do "./text.txt";
print "$name\n";
prints:
My Full Name with middle initial
> > The problem I'm having is my print statement just prints a new line
> >
Benjamin Jeeves,
You can probably figure this out. Try running the code below supplying
whatever file name you choose to save it as for an argument.
#!/usr/bin/perl -w
use strict;
my $filein = $ARGV[0];
print "$filein\n";
open(FILEIN, $filein);
my $counter = 0;
my $counter1;
&start;
sub start
Peter,
#!/usr/bin/perl -w
use strict;
my %date_formats = (
ccyymmdd => { now => sub {
my @arr = localtime();
print 'Year ', 1900 + $arr[5] . ' Month '. sprintf("%02d",$arr[4] + 1)
. ' Day ' . sprintf("%02d",$arr[3]);
}
} );
& { $date_formats{ccyymmdd}{now} };
Same output as previous
Peter
I saw Jenda's note and I suggest the code needs simplification.
> P.S. you can see where I comment out the ccyymmdd_now function. That
> approach works, but is not what I'm shooting for.
>
> %date_formats = (
> # "ccyymmdd" => {now => \ccyymmdd_now()},
> "ccyymmdd" => {now => s
Oops!
$ perl -e '
@z = qw( 3d20m 5d2h 2h2s );
for $v (@z){
$v =~ s/d/*24*3600 +/;
$v =~ s/h/*3600 +/;
$v =~ s/m/*60 +/;
$v =~ s/s/ +/;
chop $v;
$k = eval $v;
print "$v = $k seconds";
print "\n";
}'
3*24*3600 +20*60 = 260400 seconds
5*24*3600 +2*3600 = 439200 seconds
2*3600 +2 = 7202 seconds
But
Dan
> I have a string, which is to represent a length of time, say 3d4h45m12s
$ perl -e '
$v = "3d7h36m14s";
$v =~ s/d/*24*3600 +/;
$v =~ s/h/*3600 +/;
$v =~ s/m/*60 +/;
$v =~ s/s//;
$k = eval $v;
print "$v = $k seconds";'
3*24*3600 +7*3600 +36*60 +14 = 286574 seconds
And a question. Can the 4 $v
Ed,
>
> [esickafus@webserv01 Storable-2.05]$ perl Makefile.PL
> PREFIX=/home/sites/site61/users/esickafus/lib
>From the above I deduce you are trying to install modules without root
access. True?
http://www.cgi-interactive.co.uk/cpan_installing_perl_modules.html
Can possibly be of some help. I foun
Sophia, et al
> If you know in advance the array index then use splice.
If you know only the value you want to remove (and you like map...):
#/usr/bin/perl -w
use strict;
my %compilers = (
system1 => ['compiler_a'],
system2 => ['compiler_b', 'compiler_c','compiler_d'],
system3 => ['compiler_e'],
> Hi listers,
Hodwy!
> i am a perl beginner with an interesting problem (to me atleast :).
>
> Problem Overview
> -
> Somewhere on the world wide web, exists an asp page with the following
> form -
>
These look like 'specs', cool! And I think this format will generate alot of
goo
Jason,
You didn't say anyting about the OSs involved, but the '\n' *nix eoln
versus win '\r\n' is an often encountered problem.
if you are *nix and target is or may be win
while (my $line = $Telnet->getline(Timeout => 5,)) {
$line =~ s/\r\n$\\;
chomp $line;
...
might do th
$ perl -e '
$minuend = 'red';
$subtra = 'Hellored';
$res = $subtra =~ s/$minuend//;
print $minuend, "\t", $subtra, "\t", $res;'
red Hello 1
$res flags success/fail. If you would like $subtra to remain unchanged
assign
$dif = $subtra
then
$res = $dif =~ s/$minuend//;
HTH
"Pavle Lukic" <[EMAI
$ perl -e '
%hash = (
"h" => 100,
"a" => 2000,
"z" => 50,
"b" => 600
);
for(sort { $hash{$b} <=> $hash{$a} } keys %hash) {
print $hash{$_}, " = $_\n";
}'
2000 = a
600 = b
100 = h
50 = z
HTH
"Rajendra Babu" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROT
Gary,
is there always a space before the postal code? If so include it as:
if ($$line=~/^(.*)\s(\D{1,2}\d{1,2}\s{0,1}\d\D{2})\s*/) {
otherwise you may be leaving to chance where the regex engine finds a match
HTH
"Gary Stainburn" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMA
ActiveState docs suggest you can:
perl -pi '.orig' -e 's/bar/baz/' fileAto specify the .orig suffix but
That did not work for me.
perl -pi.bak -e 's/bar/baz/' fileA does! Thanks John
"John W. Krahn" <[EMAIL PROTECTED]> wrote in message
[EMAIL
JLW,
perl -pi -e 's/foo/bar/' my_file.txt
is supposed to do an inplace edit of my_file.txt, looping over each line,
replacing foo with bar. Instead it merely stomps my_file.txt, effectively
erasing it. Any body know why?
Perl for cygwin, WinNt is the environment.
David
"Jeff Westman" <[EMAIL PR
Bob,
Consider:
cls.pl
use strict;
my @switches = @ARGV;
foreach(@switches) {
print"$_\n";
}
$ perl -e '
my @clss = ("cls.pl", "one", "two", "three");
system @clss;'
output:
one
two
three
Takes the first element treats it as an executable and the rest of the list
as arguments.
HTH
"Bob H"
Another Way
use strict;
my @Ary = qw ( a b c d e f g h );
for(@Ary) {
print;
}
print"\n";
fisher_yates_shuffle(\@Ary);
for(@Ary) {
print;
}
print"\n";
sub fisher_yates_shuffle {
my $array = shift;
my $i;
for ($i = @$array; --$i; ) {
my $j = int rand ($i+1);
next if $i == $j;
Hope this is helpful...
Setting file associations is done by ActivePerl but if you want to use
command line parameters:
go to
My Computer,
View,
Options,
File Types
Edit the file type with the .pl extension,
Edit the 'Open' action
Include %1 %* so that the last por
Chris,
I have Activestate Perl and perl from a cygwin distribution. I keep the
seperate by the calling method. For cgi scripts that is the
#!/path/to/the/perl/I_need
from the command line
/usr/bin/perl
or
F:/Perl/bin/perl
The perl that accessed the debugger has it in it's @INC array as drieux
Try:
use File::Basename;
my $direx = 'E:/Perl/bin/extra/nodir/hi.txt';
my ($name, $path, $suffix, @stuff);
while (1) {
($name, $path, $suffix) = fileparse($direx);
last if $name eq '.';
print "Name is $name\n";
push @stuff, $name;
chop($path);
$direx = $path;
}
foreach (@stuff) {
print"\t$
Anadi,
http://lists.perl.org/
will take you to the right place.
beginners-cgi is what you are after. Check out dbi-users also. DBI will open
access to many other databases (I use Oracle and 2 free ones MySql and
Postgresql)
-David
"A Taylor" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">
Anadi,
Thanks, but not really...
The
#!D:\Perl|bin\perl -w
is ignored in windows - the key is the file association ( the My Computer,
View, Options stuff). Once windows knows which program is supposed to open a
particular file extension it should be off on running, but I had you put the
#!D:..
Uh,... no (atleast IMHO)
SELECT MAX(prop_rank)...
would be a more efficient approach
HTH
"A Taylor" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> howdy all,
> I was wondering if you could help me, I have a perl script that executes a
> SQL statement:
>
> 'SELE
Bryan,
There are other instances than the example below but this one tripped me
recently.
my %exhash = ( one => 1,
two => 2,
thr => 3 );
my $href = \%exhash;
my @exary = qw ( zero one two thr four);
print $$href{$exary[$$href{two}]}, "\n";
# $$href{two} is 2
# use
Jose,
try:
$ perl -e '
my $delta;
$delta = `diff ae.txt ae.txt`;
print $delta."\n";
unless ($delta) {
print"they are identical\n";
}'
HTH
"Jose Torres" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi,
>
> If I'm calling the diff program from within a Perl
Barry,
Check out
http://stein.cshl.org/WWW/software/CGI/cgi_docs.html
because the author of the CGI module shows a few neat tricks I have not seen
elsewhere, For instance, if you needed to iterate over an 'array of arrays'
to display the results of a database query and you want to display the
7;Japhy' Pinyan" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> On May 10, Dave K said:
>
> >my $p1 = join('|', (512..520));
> >my $p2 = join('|', (528..568));
> >my $p3 = join('|', (576..
Dave,
One possiblity:
use strict;
open(IN, "lfile.txt"); # ho;d the line from the example in the orig post
my $p1 = join('|', (512..520));
my $p2 = join('|', (528..568));
my $p3 = join('|', (576..578));
my $p4 = join('|', (592..600));
my $p5 = join('|', (608..622));
my $p6 = join('|', (624..6
Jason,
Play with the script below:
my @a1 = qw( one ace );
my @a2 = qw( two deuce );
my @a3 = qw( thr tri );
my @a4 = qw( fou quad );
my @a5 = qw( fiv quat );
my @myarray = (\@a1, \@a2, \@a3, \@a4, \@a5);
foreach my $item (@myarray) {
my($item1, $item2) = @$item;
print "$item1 and $item2
Just curious, Josef - are you using Windows and have you adjusted the file
type binding for open? If you are using windows and have not adjusted the
binding do so as follows:
goto My Computer, View, Options, File Types. Then find the perl .pl
extension and edit the file type, edit the open action,
I am using Windows.
$file = 'D:\\test.txt';
should help out
as will the good advice about checking to see if the open succeeds
"Josef E. Galea" <[EMAIL PROTECTED]> wrote in message
002201c1f07d$15712780$b9669ec3@josvio">news:002201c1f07d$15712780$b9669ec3@josvio...
Hi
I am a student an I'm new
David Gray,
Thanks for the input. Below is another realization using a pseudohash.
Some of the code (print stmts at the end)
is there to demonstrate concepts (the way your post did).
my $sql = "select methodid, method, sname from method order by methodid";
my $sth = $dbh->prepare($sql) or die
First let's let the other list member in on the code:
use DBI;
use strict;
my $dbname = "test";
my $host = "localhost";
my $dbuser = '';
my $dbpw = '';
my $mscs = "dbi:mysql:dbname=$dbname;host=$host;";
my $dbh = DBI->connect($mscs, $dbuser, $dbpw) or die "Connect fails to
$dbname\nError = ", $DB
Here is one script I used to inspect files
use strict;
my $fn;
print"Enter the name of a file you want to examine ";
while (<>) {
$fn = $_;
last if $fn;
}
print "Opening $fn\n";
open TF, "$fn" or die "Cannot open $fn:$!\n";
my @ov;
my $ov;
while () {
@ov = unpack('U*',$_);
print;
print"\t\t"
Bruce:
use warnings;
use strict;
use DBI;
my $dbname = 'Bruce';
my $dbhostname = 'localhost';
my $user = 'root';
my $password = '' ;
my $cs = "CREATE TABLE employee_Info (primary_key INT AUTO_INCREMENT NOT
NULL, name CHAR(20), surname CHAR(20), employee_no CHAR(10), shoe_colour
CHAR (
I have found ActiveState to be the 'easiest' in most cases but when I want
to do something fun or interesting I often find the module that I need is
not available for the ActiveState distribution. Cygwin is fun, but CPAN is
sometimes frustrating though it is sometime the only place to get a requir
I use cygwin (with and without perl) and ActiveState perl in a variety of
situations. To modify @INC so that Apache uses the right one in the right
situation I was using a begin block to modify @INC where needed. Then I
thought a module might be more to the point:
#!E:/Perl/bin/perl -w # my path
Thomas,
Any editor (I use notepad, WinVim, and anything else available - later
you may find reason to look for a 'better' editor and there is always plenty
of opinion available about editors).
With windows, you can set a file extension association by clicking in My
Computer, View, Options.
The question is a bit fuzzy, but try this at the command line, just for fun:
perl -e 'my $line = "abrabracadabra";print $line++, " ", $line, "\n";'
then consider this:
#!D:/cygwin/bin/perl
my ($i, $line, $nextline);
open (TEXTF, "c:/temp/somelines.txt") or die "Evil forces keep me for doing
what
For most rdbms you would use ALTER TABLE, for postgresql you can't.
Lets say you originally created
CREATE TABLE example (
col1 varchar,
col2 varchar,
colthree numeric);
then realized colthree was in the wrong table.
you can:
CREATE TABLE temp
AS SELECT col1,col2 FROM example;
DROP TABLE EXAMPLE;
47 matches
Mail list logo