Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

The Monastery Gates

( #131=superdoc: print w/ replies, xml ) Need Help??

Donations gladly accepted

If you're new here please read PerlMonks FAQ
and Create a new user.

New Questions
Setting syslog layout with log4perl
1 direct reply — Read more / Contribute
by neilwatson
on Aug 27, 2014 at 10:52

    Greetings

    This is my first dive in log4perl. I'm trying to configure for syslog, but I get the error ERROR: trying to set layout for SYSLOG to '%-5p %C - %m%n'. What is the correct way to configure the layout?

    log4perl.rootLogger=DEBUG, SYSLOG log4perl.appender.SYSLOG = Log::Dispatch::Syslog log4perl.appender.SYSLOG.min_level = debug log4perl.appender.SYSLOG.ident = logging.pl log4perl.appender.SYSLOG.facility = daemon log4perl.appender.SYSLOG.layout = %-5p %C - %m%n

    Neil Watson
    watson-wilson.ca

CGI files and Dancer coexisting?
1 direct reply — Read more / Contribute
by einhverfr
on Aug 27, 2014 at 04:59
    Hi;

    I am trying to write some scaffolding to support moving LedgerSMB to Dancer. Unfortunately I have had very little success at first. I tried to use Dancer::Plugin::FakeCGI and got errors during the import process. Tracing these, it looks like the module does not work with recent versions of HTTP::Headers.

    So I am wondering if this is even the right way to go about things. Should I try to run these perhaps as different PSGI apps under the same app.psgi and use work I have done to run the old cgi apps under Starman and FCGI instead? Is there another option I haven't thought of?

    I am mostly looking for strategic help and a pointer in the right direction.

Hygienic eval of templates with perl code?
1 direct reply — Read more / Contribute
by LanX
on Aug 26, 2014 at 23:28
    Hi

    I have the feeling of reinventing the wheel and would like to see other solutions...

    I'm evaling code text which is composed of 2 snippets which are supposed to be correct in isolation.

    Take as example using B::Deparse to back engineer a functions code and then wrapping new code around it before evaling. (something like this is shown in the Perl Hacks book)

    Now this additional code could contain new symbols (identifiers) like variables, subnames or labels which might shadow equally named symbols in the original code.

    This is known as Hygiene Problem.

    I decided to solve this with a template system where new symbols need to be placeholders, which are renamed (extended with a suffix) if they conflict with old symbols.

    Did anybody already try to solve this on CPAN?

    I'd like to compare different approaches.

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

Mock/Fake network fileshare for my new modules Test Suite
2 direct replies — Read more / Contribute
by Galdor
on Aug 25, 2014 at 18:38

    Dear esteamed Monks of Perl - I am writing a script/suite/module to recurse and test the various files/folders found on a network filesystem that need to have certain naming conventions, folder structures, relative paths to each other, and contents in certain files (similar to Perls' Manifest, Changes, ...) - in fact quite similar to Perl Modules structures..(actually this is to test the quality of a PROD and DEVEL ITIL DML)

    I have been persuaded to use TDD (Test Driven Development) and would like to start with this project.

    My question is this: I am pursuing test driven development - so can I have a test (mock) "share" (Windows UNC in this case) that I can "load" with samples of both correct and incorrect standards to run the tests against (with ok(); is(); isnt();, etc)?

    Also this would go into the modules distribution (as the test suite) so it would have to be as small as possible (the real DML is enormous with massive files, *.iso, *.cab, *.7z, *.zip, etc).

    PS - Another (advanced) point is that I am developing my code on laptop - so how can I "switch" test suite (prove command) to run against a) network share when in office, and b) "mock" share when traveling/at home? Also to switch between production and test DMLs

    PPS - If there are any modules that already do this kind of thing (testing directory structure integrity) please give a shout out :-)

Different values while applying format specifiers
4 direct replies — Read more / Contribute
by perlmonksuser
on Aug 25, 2014 at 13:51
    $a=5.10; $c=10.10; $b=$a*100; $d=$c*100; printf("%d\n",$b); printf("%u\n",$d);

    This gives me the output 509 and 1010. However when I just use print and log the values I get 510 and 1010. Why is there a difference when I use %d and %ld in case of printf/sprintf?

Type of arg 1 to push must be array (not private variable)
2 direct replies — Read more / Contribute
by natxo
on Aug 25, 2014 at 09:03
Device::BCM2835, hardware access on a pi, SIGSEGV
2 direct replies — Read more / Contribute
by Peterpion
on Aug 25, 2014 at 06:22

    Greetings monks.

    I am trying to use peri_read and its associated peri functions in the module Device::BCM2835 and failing miserably. I hit seg faults with every slight use of the peri functions and I can't work out what I am doing wrong, to the point of suspecting a fault with the module or its installation.

    First, briefly - why am I trying to use low level access? I need to toggle groups of bits on a raspberry pi GPIO interface at high audio frequencies and setting individual bits one by one in perl is proving too slow. I believe that if I write a whole byte to the register at once I will probably hit my speed requirements. I have got it all working fine in C, but I am doing something which needs rapid code modifications (as I modify the hardware) which perl suits far better hence my attempts here.

    But the documentation for the Device::BCM2835 module is quite sparse regarding the 3 peri functions and there are no examples, which is probably why I can't 'get it'. Although there are no examples of people using these functions on the searchable web, and so I doubt anyone here will have played with them personally, I wonder if more experienced eyes cast over the docs will detect my mistake.

    Essentially I am doing this:

    $|=1; use Device::BCM2835; Device::BCM2835::init()|| die "Could not init library"; my @pins = (&Device::BCM2835::RPI_GPIO_P1_07, &Device::BCM2835::RPI_GPIO_P1_11,&Device::BCM2835::RPI_GPIO_P1_12, &Device::BCM2835::RPI_V2_GPIO_P1_13,&Device::BCM2835::RPI_GPIO_P1_15, &Device::BCM2835::RPI_GPIO_P1_16,&Device::BCM2835::RPI_GPIO_P1_18, &Device::BCM2835::RPI_GPIO_P1_22); Device::BCM2835::gpio_fsel($_, &Device::BCM2835::BCM2835_GPIO_FSEL_OUT +P) for @pins; Device::BCM2835::peri_write(&Device::BCM2835::BCM2835_PERI_BASE + 0x2 +00000, 0x1C); print "No seg fault!!\n";

    I have tried various permutations (many) of the peri_write arguments but all have the same effect, which is immediate seg fault.

    Perhaps I am mixing access methods, but it seems to me I need to set the hardware pin modes one way or another and using the higher level methods would seem to be fine, after all the regisers will remain in the state I set them to (using fsel).

    The code works fine if I use Device::BCM2835::gpio_write instead of peri_write but that only sets a single bit at a time.

    I suspect my address arguments to peri_write are wrong, but I have tried several different ones, using the constants as well as the actual physical addresses which the function apparently takes. I can't find the actual perl in the module which the various functions are defined in so I have not been able to really see what the function peri_write looks like. I suspect the peri_write function is just a wrapper round the C, but looking at the C function it seems it should take the physical numerical addresses I have tried. So I am at that unhappy point of not knowing what to try next, and hoping that a wise monk could point me in the right direction.

    TIA, Pete
Defining hash structure
2 direct replies — Read more / Contribute
by mtx
on Aug 25, 2014 at 04:58
    Hello guys, im a newbie at Perl, my apologies if I ask something that is weird. Im having a trouble here for an exam, it requires me to use this input:
    Slot Description HW Version Software Version Uptime 0 CAM (0D, 12U) CAM-01122W/K04 CMTS_V07.03.01.39 112 days 2:26: +09 1 CAM (0D, 12U) CAM-01122W/K04 CMTS_V07.03.01.39 112 days 2:26: +09 2 CAM (0D, 12U) CAM-01122W/K04 CMTS_V07.03.01.39 112 days 2:26: +09 3 CAM (0D, 12U) CAM-01122W/K04 CMTS_V07.03.01.39 112 days 2:26: +10 4 CAM (0D, 12U) CAM-01122W/K05 CMTS_V07.03.01.39 112 days 2:26: +10 5 CAM (0D, 12U) CAM-01122W/K04 CMTS_V07.03.01.39 112 days 2:26: +09 6 CAM (0D, 12U) CAM-01122W/K04 CMTS_V07.03.01.39 112 days 2:26: +10 Press <space> to continue, <cr> to single step, ? for help 7 CAM (0D, 12U) CAM-01122W/K05 CMTS_V07.03.01.39 112 days 2:26: +09 8 CAM (0D, 12U) CAM-01122W/K05 CMTS_V07.03.01.39 112 days 2:26: +10 9 CAM (0D, 12U) CAM-01122W/K05 CMTS_V07.03.01.39 112 days 2:26: +10 10 CAM (16D, 0U) CAM-20016W/G04 CMTS_V07.03.01.39 112 days 2:29: +46 11 CAM (16D, 0U) CAM-20016W/G04 CMTS_V07.03.01.39 112 days 2:30: +15 12 CAM (16D, 0U) CAM-20016W/G04 CMTS_V07.03.01.39 112 days 2:29: +51 13 CAM (16D, 0U) CAM-20016W/G04 CMTS_V07.03.01.39 112 days 2:29: +33 14 CAM (16D, 0U) CAM-20016W/G04 CMTS_V07.03.01.39 112 days 2:29: +47 15 CAM (16D, 0U) CAM-20016W/G04 CMTS_V07.03.01.39 112 days 2:29: +52 Press <space> to continue, <cr> to single step, ? for help 17 RCM A RCM-01000W/E04 CMTS_V07.03.01.39 112 days 2:29: +24 18 RCM B RCM-01000W/E04 CMTS_V07.03.01.39 112 days 2:28: +22 19 SCM A SCM-02440W/B10 CMTS_V07.03.01.39 112 days 2:32: +51 20 SCM B SCM-02440W/B10 CMTS_V07.03.01.39 112 days 2:32: +51
    and output the following structure:
    my %slotHash = ( "9" = ( type => "CAM", #The first three characters of the descr +iption slotID => 9, description => "CAM (0D, 12U)", hwVersion => "CAM-01122W/K05", swVersion => "CMTS_V07.03.01.39", uptime => 9685570 ), "17" = ( type => "RCM", #The first three characters of the descr +iption slotID => 17, description => "RCM A", hwVersion => "RCM-01000W/E04", swVersion => "CMTS_V07.03.01.39", uptime => 9685764 ), );

    Can you guys point me in the right direction?

    Im having problems how to declare a hash like this, this input is weird, maybe I can change the input to a delimiter or something, if I do this, how can I do the hash with this specific structure? THANKS!
making random number
5 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 25, 2014 at 02:00

    Hi friends,i am beginner in Perl and i want to make random numbers say with 11 digits which begins for example with 912.could you please help me? for example 1000 number.

Which Module for Dates?
4 direct replies — Read more / Contribute
by jrefior
on Aug 24, 2014 at 23:53

    Hello, I am writing a Finance::StockAccount set of modules to analyze the past transactions in a personal stock account. I hope to distribute this on CPAN. Dates are incidental to this: I need to be able to import transactions with dates and compare dates to sort chronologically. I want to make it easy to use my modules, including when importing dates or setting a date using a string.

    There are plenty of CPAN modules related to dates, including parsing, comparing, and formatting for display. So there is no reason for me to reinvent the wheel here. So far, I am thinking of using DateTime, the choice appears to be simple and defensible, as it seems so standard, is so robust, and there is so much built around it. DateTime::Format::CLDR and DateTime::Format::Flexible look like relatively standard and easy ways to import dates from strings. So then some of my classes will have a "date" property like date => $dt. Others will have methods that sort transactions by date using the DateTime->compare method.

    That's all fine for me. But is that fine for the people who might use my module? Is there a standard or recommended way to handle dates in CPAN modules? Is a dependency on DateTime okay? DateTime has a lot of dependencies itself. I see Time::Moment is lighter weight, should I worry about performance? Any other thoughts/suggestions?

    Thanks very much for your help.

    John

keep only unique elements in an array displaying number of duplicates.
3 direct replies — Read more / Contribute
by john.tm
on Aug 24, 2014 at 12:05
    I have to run a report from a csv file, i am stuck on the part where i want to keep only unique elements from column 1,if column 5 matches a certain string, displaying the count of how many duplicates there were.

    I can get the count of all the names in the list with how may times thay appear but am lost on how to do a (while column1 and if column 5 = "????") bit

    input col1 col5 output james yes james 2 dave yes dave 2 mike yes mike 3 ken no ken 1 jon yes jon 4 jon no ken yes jon yes mike no james yes dave yes mike no ken no jon yes jon yes
    this is a snippet of what i have so far
    my %seen; while (<INPUT>) { chomp; my $line = $_; my @elements = split (",", $line); my $col_name = $elements[1]; my $col_type = $elements[5]; $seen{$col_name}++; } while ( my ( $col_name, $times_seen ) = each %seen ) { my $loc_total = $times_seen ; print " $col_name\t\t: $loc_total\n"; }
Accessing many-to-many relationships in Catalyst
1 direct reply — Read more / Contribute
by LunarCowgirl
on Aug 23, 2014 at 19:23

    I'm sure the answer is probably simple, but I haven't yet stumbled onto it. I've been learning DBIx::Class with Catalyst. So far I've been able to figure out how they work together, but I'm stuck on one issue.

    I have a many-to-many relationship that joins together three tables which are basically called "page", "chapter", and "book". I can gather resultsets and pass them into Template Toolkit, using them as such:

    [% page.book.title %]: [% page.chapter.num %]

    which prints out the title and chapter number of the book. My questions is: how can I do that within Catalyst itself? I'm setting up an RSS feed, and I need access to "page.book.num" and "page.chapter.num" to create a url within the feed. I've tried both variations below, as well as others:

    # Gets latest 10 results my $rs = $c->model('DB::Page')->get_rss; while ( my $page = $rs->next ) { my $book = sprintf( "%02d", $page->book->{num} ); my $chapter = sprintf( "%02d", $page->chapter->num ); ... }

    Neither of those work. The first returns "00". The second produces an error that "num" can't be found. Is there any simple way to do this?

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-08-28 01:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (254 votes), past polls