Newbie needs help

2011-03-22 Thread Geospectrum
Hi am am setting up a small website and have set up formmail.pl to
create a way of people asking questions.

I'd like now to add a way of visitors to display a HTML page by
entering a number (invoice number) into a HTML form and then retrieve
a html page. So I create a html page called http://www.mysite/1234.html
and the user types in 1234 into the form and the page 
http://www.mysite/1234.html
is retrived and displayed.

I imagine I could use the perl script to create the full url and
display the page by conctenating the domain name, invoice number
and .html but I really have no idea about how to do this. Can I use
the GET method of the form? I am hoping someone can point me towards a
tutorial or offer up some snippets.

Thanks


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Newbie needs help

2011-03-22 Thread shawn wilson
On Tue, Mar 22, 2011 at 1:05 PM, Geospectrum  wrote:

> Hi am am setting up a small website and have set up formmail.pl to
> create a way of people asking questions.
>
> I'd like now to add a way of visitors to display a HTML page by
> entering a number (invoice number) into a HTML form and then retrieve
> a html page. So I create a html page called http://www.mysite/1234.html
> and the user types in 1234 into the form and the page
> http://www.mysite/1234.html
> is retrived and displayed.
>
> I imagine I could use the perl script to create the full url and
> display the page by conctenating the domain name, invoice number
> and .html but I really have no idea about how to do this. Can I use
> the GET method of the form? I am hoping someone can point me towards a
> tutorial or offer up some snippets.
>
>
> lets go simple and then go pro here.

simple (bad) use cgi get. so www.example.com/script.pl?1234

and do something like (untested, should work):
my $page = $cgi->param( 'page' );
print $cgi->redirect( $page . ".html" );

however, you probably want to use template toolkit if you're doing simple
perl pages. personally, i use catalyst and javascript to render data (so i
don't do too much in template toolkit).

if you do catalyst, you might setup a model that looks something like this:
my $page = $c->req->param->{page};
$c->forware( "View::" . $page );

which would forward you to that tt view when you get that request. i don't
like either of these ways of doing it and if you wanted to do exactly as you
asked, just open a file handle and dump. though, my preference really is to
return json data and use js to render :)

also, this is more meta code than code - you need to do checking and what
not. i'm not sure if cgi.pm does anything to prevent me from doing:
www.example.com/script.pl?page=rm%20-rf%20%20
which may do something like:
rm -rf / .html
(html wouldn't match but / would - not good)


Re: shift oo

2011-03-22 Thread Randal L. Schwartz
> "Peter" == Peter Scott  writes:

>> my $s = Streamer->new;
>> my $app = sub {
>> return sub {
>> $s->open_fh;
>> my $writer = shift->(
>> [ 200, [ "Content-type" => "text/plain" ], $s ]
>> );
>> };
>> };

Peter> As it stands, this doesn't make sense because nothing happens to 
$writer; 
Peter> so why create it?

I presume you're objecting to the explicit $writer.  Certainly, the
value of $writer is also the return value of the inner subroutine, so
that *is* something that could be noted:

my $whatever_writer_was = $app->(somearg_for_that_inner_shift);

This looks like the PSGI interface.  Would have been nice to spell that
out too, since there's a wealth of info on that already.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
 http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Newbie needs help

2011-03-22 Thread Randal L. Schwartz
> "Geospectrum" == Geospectrum   writes:

Geospectrum> Hi am am setting up a small website and have set up formmail.pl to
Geospectrum> create a way of people asking questions.

I'm so very much hoping that you're not using Matt Wright's original
formmail.pl, and instead using the one from NMS.  Even Matt now tells
you to go get NMS:

   http://www.scriptarchive.com/nms.html

Yes, Matt's a good guy... even he knows when he's been beaten. :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
 http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: foreach loop

2011-03-22 Thread Chris Stinemetz
>>No, it doesn't. What is a "rlptxat" element? Where do they come from.

"rlptxat" is just an element indexed at 44 that has a value, in which I would 
like to sum up, when it has the same elements "cell" "sect" and "carr" in the 
record.

I hope this helps

Thank you,

Chris 

At 8:03 PM -0600 3/20/11, Chris Stinemetz wrote:
>Jim,
>
>Thanks for your feedback. I am actually trying to sum up all rlptxat 
>elements that have the same cell, sect, and chan elements in the 
>array. I hope this clarifies.

No, it doesn't. What is a "rlptxat" element? Where do they come from.

You can define a multiple-level hash with three nested keys (cell, 
sect, chan) to hold the sum of all elements with the same key values 
(a triple):

   my %sum;

Find values of cell, sect, and chan:

$cell = ?
$sect = ?
$chan = ?

Add the value with these keys to the sum:

   $sum{$cell}{$sect}{$chan} += ?

Iterate over the result:

   for my $cell ( sort keys %sum ) {
 for my $sect ( sort keys %{$sum{$cell}} ) {
   for my $chan ( sort keys %{$sum{$cell}{$sect}} ) {
   print "Value of sum($cell,$sect,$chan) is 
$sum{$cell}{$sect}{$chan}\n";
   }
 }
   }

Good luck!

-- 
Jim Gibson
j...@gibson.org

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: shift oo

2011-03-22 Thread shawn wilson
On Mar 22, 2011 4:43 PM, "Randal L. Schwartz"  wrote:
>
> > "Peter" == Peter Scott  writes:
>
> >> my $s = Streamer->new;
> >> my $app = sub {
> >> return sub {
> >> $s->open_fh;
> >> my $writer = shift->(
> >> [ 200, [ "Content-type" => "text/plain" ], $s ]
> >> );
> >> };
> >> };
>
> Peter> As it stands, this doesn't make sense because nothing happens to
$writer;
> Peter> so why create it?
>
> I presume you're objecting to the explicit $writer.  Certainly, the
> value of $writer is also the return value of the inner subroutine, so
> that *is* something that could be noted:
>
> my $whatever_writer_was = $app->(somearg_for_that_inner_shift);
>
> This looks like the PSGI interface.  Would have been nice to spell that
> out too, since there's a wealth of info on that already.
>
> --

Yes, it would appear that there was much more to this than I originally
suspected. It would seek that there is probably plack::builder and:
builder {
mount "/whatever" => $app;
}

And maybe more. Either way this was a good for a reference (sorta, kinda, ah
maybe not even that :) ). But, I did learn some cool stuff here (I think). I
got working what I wanted to get working and am now looking at ae::redis to
stream when I want.

I should probably go back at some point and make sure I know the basics.
However, for now, getting this stuff to work is more funner.

I learned a new way to use shift here (or probably any function that uses
$_) and I have (sorta learned about closures.

Now, I'm pretty sure that what was being shifted was a method probably $req
= Plack::Request->($env); and $req was being or gets passed from builder.

I might be new here but I think this is getting ot and I've been told that
plack is a month or so from 'supported' so I'll go now. Thank yall for the
help.


Re: shift oo

2011-03-22 Thread Uri Guttman
> "sw" == shawn wilson  writes:

  sw> I learned a new way to use shift here (or probably any function
  sw> that uses $_) and I have (sorta learned about closures.

you are doing it again. $_ and @_ have nothing to do with each
other. and shift never touches $_. shift works on its array argument or
@_ inside a sub or @ARGV outside a sub if no argument is passed. you
haven't learned diddly about shift IMNSHO if you keep saying wrong
things like this.

  sw> Now, I'm pretty sure that what was being shifted was a method probably 
$req
  sw> = Plack::Request->($env); and $req was being or gets passed from builder.

it doesn't matter what was shifted. what matters is that you understand
shift independently from the surrounding code. you haven't demonstrated
that to me yet. 

uri

-- 
Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com --
-  Perl Code Review , Architecture, Development, Training, Support --
-  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com -

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: foreach loop

2011-03-22 Thread Jim Gibson
On 3/22/11 Tue  Mar 22, 2011  2:24 PM, "Chris Stinemetz"
 scribbled:

>>> No, it doesn't. What is a "rlptxat" element? Where do they come from.
> 
> "rlptxat" is just an element indexed at 44 that has a value, in which I would
> like to sum up, when it has the same elements "cell" "sect" and "carr" in the
> record.

OK. With this information and that from previous posts, your requirements
may be summaryized as follows:

You have a file with one record per line, each line consisting of a number
of fields. Within each record may be found values of cell, sect, carr, and
rlptxat at fixed column positions (e.g. 44 for rlptxat). You with to sum up
the values of the rlptxat field for all records having the same values of
cell, sect, and carr.

Correct?

> At 8:03 PM -0600 3/20/11, Chris Stinemetz wrote:
>> Jim,
>> 
>> Thanks for your feedback. I am actually trying to sum up all rlptxat
>> elements that have the same cell, sect, and chan elements in the
>> array. I hope this clarifies.
> 
> No, it doesn't. What is a "rlptxat" element? Where do they come from.
> 
> You can define a multiple-level hash with three nested keys (cell,
> sect, chan) to hold the sum of all elements with the same key values
> (a triple):
> 
>my %sum;
> 
> Find values of cell, sect, and chan:

Let @record be the array containing the values from each row, as returned by
the split function, for example. Then:

 
my $cell = $record[?] # ? is column number for cell field
my $sect = $record[?] # ? is column number for sect field
my $chan = $record[?] # ? is column number for chan field
my $rlptxat = $record[44];

Or more succintly:

my( $cell, $sect, $chan, $rlptxat ) = @record[ ?, ?, ?, 44 ]; # ? as above

> 
> Add the value with these keys to the sum:
> 
$sum{$cell}{$sect}{$chan} += $rlptxat

> 
> Iterate over the result:
> 

   for my $cell ( sort keys %sum ) {
 for my $sect ( sort keys %{$sum{$cell}} ) {
   for my $chan ( sort keys %{$sum{$cell}{$sect}} ) {
   print "Value of sum($cell,$sect,$chan) is " .
 $sum{$cell}{$sect}{$chan} . "\n";
   }
 }
   }

And you are done.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: foreach loop

2011-03-22 Thread Chris Stinemetz
Jim,

You hit it right on. This is exactly what I am trying to do.

> OK. With this information and that from previous posts, your requirements may 
> be summaryized as follows:

> You have a file with one record per line, each line consisting of a number of 
> fields. Within each record may be found values of cell, sect, carr, and 
> rlptxat at fixed
> column positions (e.g. 44 for rlptxat). You with to sum up the values of the 
> rlptxat field for all records having the same values of cell, sect, and carr.

> Correct?

I took your advice but I am still unable to get the results I want.

Below is what I have with your code added. I also changed it from $fh to  
so you can get an idea of the input data
and copy and paste it if you need to.

Thanks for a all your help!

Chris

#!/usr/bin/perl

use warnings;
use strict;


#my $filepath = 'C:/temp/PCMD';
#my $filepath = 'C:/cygwin/home/cstinemetz/perl_programs/1.EVDOPCMD';
#my $outfile  = 'output.txt';

#open my $fh, '<', $filepath or die "ERROR opening $filepath: $!";
#open my $out, '>', $outfile or die "ERROR opening $outfile: $!";

my @records = ();

while (){

next unless /;/;
chomp;
my @data = split /;/;
my($cell,$sect,$chan,$carr,$rlptxat,$dist,$precis) = 
@data[31,32,38,39,44,261,262];

# my %sum

# $sum{$cell}{$sect}{$chan} += $rlptxat

# for my $cell ( sort keys %sum ) {
# for my $sect ( sort keys %{$sum{$cell}} ) {
# for my $chan ( sort keys %{$sum{$cell}{$sect}} ) {
# print "Value of sum($cell,$sect,$chan) is " .
# $sum{$cell}{$sect}{$chan} . "\n";
# }
# }
# }



$carr =
( $chan == 75 )   ? 2 :
( $chan == 1025 ) ? 2 : 1 ; #nested ternary operator

$dist =
( length( $dist ) > 1 ) ? $dist/6.6/8/2*10/10 : '' ;


push @records, {
cell   => $cell,
sect   => $sect,
carr   => $carr,
chan   => $chan,
RTD=> $dist,
Precis => $precis,
};
}

my @sorted = sort {
$a->{cell} <=> $b->{cell} ||
$a->{sect} <=> $b->{sect} ||
$a->{carr} <=> $b->{carr}
  } @records ;


for my $tuple ( @sorted ){
#print sprintf("%15s\t%10s\t%10s\n","$tuple->{cell}\t $tuple->{sect}\t 
$tuple->{carr}");
print "$tuple->{cell}\t $tuple->{sect}\t $tuple->{carr}\t $tuple->{chan}\t 
$tuple->{RTD}\n";
}
# for my $tuple ( @sorted ){
# print $out "$tuple->{cell} $tuple->{sect} $tuple->{carr} $tuple->{RTD}\n";
# }
# close $out;


__DATA__
PACE | EVDOPCMD | 33.0 | 101218 | 07 |
8;1023240136;1218;0;1;00a01a2bcdc7;0310003147702376;ac016d4a;;;5.6.128.8;0;43234169;43234349;;;1;1;1;;0;;19;5.6.128.22;172.30.151.5;304;3;304;3;15;175;15;175;15;175;1;1798;1251;0;0;2;19;20;1;1;1;0;128;5.6.128.8;;;301;5.6.128.8;;;8;304;31;43244037;;;1;18;43234169;01;;43234416;0;0;304;3;21;19;175;15;405;1;1;1;1;0;125;1||
8;1023240137;1218;0;1;00a01db74ace;;ac0174ca;43243423;1678442111;5.6.128.8;1;0;;43242544;43244207;43243423;43243647;;;1000;1;1;;0;;19;5.6.128.26;;372;2;372;2;;43243012;0;43243562;15;175;15;175;15;175;1;5;48;19;20;49;50;;0;1;2;0;68;5.6.128.8;;;301;5.6.128.8;;;8;372;21;43244207;;;1;18;43243423;01;;43242544;0;0;372;2;21;19;175;15;177;3;1;0;0;0;68;1|43243753;0;0;372;2;21;19;175;15;177;3;1;1;1;0;71;1|
8;1023240138;1218;0;1;00a02017ccdb;0310003147833882;aca344d7;;;5.6.128.13;0;43234160;43234358;;;1;1;1;;0;;19;5.6.128.31;172.30.151.5;320;2;320;2;15;75;15;75;15;75;1;2162;1317;0;0;2;19;20;1;1;1;0;104;5.6.128.13;;;306;5.6.128.13;;;8;320;21;43244164;;;1;18;43234160;01;;43234404;0;0;320;2;21;19;75;15;279;6;1;1;1;0;64;1||
8;1023240139;1218;0;1;00a109237b21;0310003147774000;aca3141e;;;5.6.128.13;0;43235644;43235820;;;9000;1;1;;0;;19;5.6.128.19;172.30.151.5;502;1;502;1;15;175;15;175;15;175;1;48;79;0;0;2;19;20;1;1;1;0;124;5.6.128.13;;;306;5.6.128.13;;;8;502;11;43244194;;;1;18;43235644;01;;43235887;0;0;502;1;21;19;175;15;27;1;1;1;1;0;127;1;

RE: foreach loop

2011-03-22 Thread Jim Gibson

At 9:58 PM -0600 3/22/11, Chris Stinemetz wrote:

Jim,

You hit it right on. This is exactly what I am trying to do.

 OK. With this information and that from previous posts, your 
requirements may be summaryized as follows:


 You have a file with one record per line, each line consisting of 
a number of fields. Within each record may be found values of cell, 
sect, carr, and rlptxat at fixed
 column positions (e.g. 44 for rlptxat). You with to sum up the 
values of the rlptxat field for all records having the same values 
of cell, sect, and carr.



 Correct?


I took your advice but I am still unable to get the results I want.

Below is what I have with your code added. I also changed it from 
$fh to  so you can get an idea of the input data

and copy and paste it if you need to.



But you commented out my code, and deleted the part that prints the 
results. Your code does not sum anything. You don't need to sort the 
records to produce a sum.


Run your data through my code and see what you get. Then explain why 
it does not do what you want.


--
Jim Gibson
j...@gibson.org

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/