[32919] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4197 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 19 03:09:30 2014

Date: Sat, 19 Apr 2014 00:09:02 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 19 Apr 2014     Volume: 11 Number: 4197

Today's topics:
    Re: Building on Cygwin <rweikusat@mobileactivedefense.com>
    Re: Building on Cygwin <rweikusat@mobileactivedefense.com>
        Mod 10A lisapigeon@gmail.com
    Re: Mod 10A <gravitalsun@hotmail.foo>
    Re: Pathname from URL <gravitalsun@hotmail.foo>
        simple, practical example of "code-reuse with the help  <rweikusat@mobileactivedefense.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 18 Apr 2014 16:37:48 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Building on Cygwin
Message-Id: <87vbu64pir.fsf@sable.mobileactivedefense.com>

Nigel <njh@despammed.com> writes:
> To date I have been able to build Perl on Cygwin with no problems but
> on a new machine I have had problems.  Any version that I try to build
> gives error when trying to compile cygwin.c:
>
> nostdio.h:25:14: error: two or more data types in declaration specifiers
>  #define FILE struct _FILE
>
> Any ideas?

NB: This is not really related to Perl.

You could try to run the .c file through the preprocessor, delete all
preprocessing directives from that and try to compile the
result[*]. This should result in the same error message but you'll find
the actual code the compiler couldn't processed on the corresponding
line of the input file.

[*] Simplistic example based on gcc:  When trying to compile following .c file,

------
#define printf (1 + 2)

#include <stdio.h>

int main(void)
{
    return 0;
}
------

an error message

In file included from a.c:3:
/usr/include/stdio.h:339: error: expected identifier or '(' before numeric constant

is printed. Line 339 of stdio.h is the printf prototype. Applying the
procedure suggested above,

[rw@sable]/tmp#gcc -E a.c >x.c
[rw@sable]/tmp#ed x.c <<TT
> g/^#/d 
> wq
> TT
17145
13674
[rw@sable]/tmp#gcc x.c
x.c:418: error: expected identifier or '(' before numeric constant
[rw@sable]/tmp#cat -n x.c | awk '{ if ($1 == 418) print $0; }'
   418  extern int (1 + 2) (__const char *__restrict __format, ...);

That's not of much use for this contrived example, but usually helpful
in case of less trivial macro arrangements.


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

Date: Fri, 18 Apr 2014 17:11:49 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Building on Cygwin
Message-Id: <87ioq64ny2.fsf@sable.mobileactivedefense.com>

Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:

[...]

> [rw@sable]/tmp#cat -n x.c | awk '{ if ($1 == 418) print $0; }'
>    418  extern int (1 + 2) (__const char *__restrict __format, ...);

More on topic: While this also qualifies for an 'awkward use of
awk'-award, a nicer way to express this in perl would be

perl -ne '$. == 418 and print' <x.c

or

perl -ne '$. == 418 and print, exit' <x.c

in case the file is large enough that uselessly processing the remainder
ought to be avoided.


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

Date: Fri, 18 Apr 2014 08:39:02 -0700 (PDT)
From: lisapigeon@gmail.com
Subject: Mod 10A
Message-Id: <f08bbd51-6f73-4ab2-8d7c-64c9a26482b8@googlegroups.com>

Can anyone tell me what is the difference between a basic Mod 10 and Mod 10A?

Thanks much,
Lisa


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

Date: Fri, 18 Apr 2014 18:48:25 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: Mod 10A
Message-Id: <lirhge$p4r$1@news.ntua.gr>

Στις 18/4/2014 18:39, ο/η lisapigeon@gmail.com έγραψε:
> Can anyone tell me what is the difference between a basic Mod 10 and Mod 10A?
>
> Thanks much,
> Lisa
>


print 267 % 10;
print 267 % 0x10a;



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

Date: Fri, 18 Apr 2014 18:43:22 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: Pathname from URL
Message-Id: <lirh6u$ob3$1@news.ntua.gr>

Στις 16/4/2014 12:28, ο/η Andre Majorel έγραψε:
> Looking for Perl code to convert a URL like
>
>    http://foobar.org/%7Ea/b/c?d=e/f#g
>
> to a Unix pathname like
>
>    foobar.org/~a/b/c?d=e%2Ff
>
> The same sort of thing that wget -x does.
>
> Even better if it offers the option of honouring the
> Content-disposition HTTP header.
>
> Thanks in advance !
>




#!/usr/bin/perl
use strict;
use warnings;
use feature qw/say/;
use URI;

my $url    = URI->new('http://foobar.org/%7Ea/b/c?d=e/f#g');
my $scheme = $url->scheme;

(my $what_you_want = $url->canonical)=~s/^$scheme:\/\///;
say $what_you_want;



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

Date: Fri, 18 Apr 2014 18:29:06 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: simple, practical example of "code-reuse with the help of OOP"
Message-Id: <87wqem35st.fsf@sable.mobileactivedefense.com>

One of the problems "with OOP" is that realistic examples of its use are
usually much too complicated to make good examples and that 'the usual
contrived examples' (eg, drawing shapes or dealing with animals or cars)
are too 'contrived' to be of much use. By chance, I came accross a
'real' simple example.

The problem I had to deal with was uploading a large file for processing
to an appliance with 'very limited' disk space. Because of this,
processing was supposed to work 'from the network', ie, without creating
an intermediate temporary file. CGI.pm[*] offers an 'upload hook
function' feature which can be used to handle the data as it arrives. An
additional complication was that the values of some other fields of the
same form needed to be known before the data could be processed. Clients
are required to send form fields in the order they appear in the form
so, theoretically, putting the other fields in front of the file upload
control should work.

	[*] I spend more than half of my 'professional life' buried
	below heaps and heaps of variably grotty Java code and thus
	rejoice in every opportunity to use simple solutions to simple
	problems ...

However, in practice, CGI.pm processes all input data during execution
of the init-method which is invoked immediately before the constructor
returns, meaning, there's no way the 'upload hook' function could use
the CGI object to access the other parameters. Simple OOP-solution for
that (code copyright my employer, cited for educational purposes):

--------------
package MAD::RestoreCGI;

use CGI         qw(-no_xhtml);
our @ISA =      qw(CGI);

#*  variables
#
our $delay_init;
my %inits;

#*  methods
#
sub new_hull
{
    local $delay_init = 1;
    return $_[0]->new(@_[1 .. $#_]);
}

sub init
{
    my $args;
    
    if ($delay_init) {
        $inits{$_[0]} = [@_[1 .. $#_]];
        return;
    }

    $args = $inits{$_[0]};
    delete($inits{$_[0]});

    return $_[0]->SUPER::init(@$args);
}

# Ziegenzahn-Aschenbecher
1;
--------------

The code using this invokes the new_hull ctor which returns the CGI
object but prevents the actual init-method from being executed from the
constructor itself. The init-method is then invoked explicitly to
process the CGI input after the object has been made available to the
upload-function which can then read the 'relating processing parameters'
via $cgi->param('...') in the 'usual' way.

NB: I don't claim that this is a particularly pretty or 'well-designed'
solution, but it is simple and works.


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

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 4197
***************************************


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